Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit 5d8778d

Browse files
author
Pavan Kumar
committed
[list] list should take argument
* list should take app name as argument and print its properties * additionally if no argument is provided print all available apps
1 parent a97c983 commit 5d8778d

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

apps.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ func selectionString(appNames []string) string {
5757
}
5858

5959
func (a *apps) printApp(e *env, params *app) error {
60-
w := new(tabwriter.Writer)
60+
fmt.Fprintf(e.Out, "Properties of the app %q:\n", params.Name)
6161

62+
w := new(tabwriter.Writer)
6263
w.Init(e.Out, 0, 8, 0, '\t', 0)
6364
fmt.Fprintf(w, "Name\t%s\n", params.Name)
6465
fmt.Fprintf(w, "DashboardURL\t%s\n", params.DashboardURL)
@@ -173,21 +174,25 @@ func (a *apps) selectApp(apps []*app, msg string, e *env) (*app, error) {
173174
return nil, stackerr.Newf("Please try again. Please select from among the listed apps.")
174175
}
175176

176-
func (a *apps) showApps(e *env) error {
177+
func (a *apps) showApps(e *env, appName string) error {
177178
apps, err := a.restFetchApps(e)
178179
if err != nil {
179180
return err
180181
}
181-
fmt.Fprintln(e.Out, "The following apps are currently owned by you:")
182-
app, err := a.selectApp(apps,
183-
"Select an app to view its properties: ",
184-
e,
185-
)
186-
if err != nil {
187-
return err
182+
if appName != "" {
183+
for _, app := range apps {
184+
if app.Name == appName {
185+
return a.printApp(e, app)
186+
}
187+
}
188188
}
189-
fmt.Fprintf(e.Out, "Properties of app: %q\n", app.Name)
190-
return a.printApp(e, app)
189+
190+
fmt.Fprintf(
191+
e.Out,
192+
"These are the apps you currently have access to:\n%s",
193+
selectionString(allApps(apps)),
194+
)
195+
return nil
191196
}
192197

193198
func (a *apps) getAppName(e *env) (string, error) {

apps_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ func TestCreateNewApp(t *testing.T) {
242242
`Please choose a name for your Parse app.
243243
Note that this name will appear on the Parse website,
244244
but it does not have to be the same as your mobile app's public name.
245-
Name: Name D
245+
Name: Properties of the app "D":
246+
Name D
246247
DashboardURL https://api.example.com/dashboard/D
247248
ApplicationID applicationID.D
248249
ClientKey clientKey.D

list_cmd.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ func (l *listCmd) printListOfApps(e *env) error {
2828
return nil
2929
}
3030

31-
func (l *listCmd) run(e *env) error {
31+
func (l *listCmd) run(e *env, args []string) error {
3232
l.printListOfApps(e)
3333

3434
var apps apps
3535
if err := apps.login.authUser(e); err != nil {
3636
return err
3737
}
38-
return apps.showApps(e)
38+
var appName string
39+
if len(args) > 0 {
40+
appName = args[0]
41+
}
42+
return apps.showApps(e, appName)
3943
}
4044

4145
func newListCmd(e *env) *cobra.Command {
@@ -46,6 +50,6 @@ func newListCmd(e *env) *cobra.Command {
4650
Long: `Lists Parse apps and aliases added to the current Cloud Code directory
4751
when executed inside the directory.
4852
Additionally, it prints the list of Parse apps associated with current Parse account.`,
49-
Run: runNoArgs(e, l.run),
53+
Run: runWithArgs(e, l.run),
5054
}
5155
}

0 commit comments

Comments
 (0)