Skip to content

Commit 6e8fd3e

Browse files
arduino-app-cli: add app ID completion Add completion for app ID, expressed in human readable form (#478)
1 parent 4713e64 commit 6e8fd3e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cmd/arduino-app-cli/app.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func newStartCmd() *cobra.Command {
7979
}
8080
return startHandler(cmd.Context(), app)
8181
},
82+
ValidArgsFunction: ApplicationNames(),
8283
}
8384
}
8485

@@ -97,6 +98,7 @@ func newStopCmd() *cobra.Command {
9798
}
9899
return stopHandler(cmd.Context(), app)
99100
},
101+
ValidArgsFunction: ApplicationNames(),
100102
}
101103
}
102104

@@ -119,6 +121,7 @@ func newRestartCmd() *cobra.Command {
119121
}
120122
return startHandler(cmd.Context(), app)
121123
},
124+
ValidArgsFunction: ApplicationNames(),
122125
}
123126
return cmd
124127
}
@@ -139,6 +142,7 @@ func newLogsCmd() *cobra.Command {
139142
}
140143
return logsHandler(cmd.Context(), app, &tail)
141144
},
145+
ValidArgsFunction: ApplicationNames(),
142146
}
143147
cmd.Flags().Uint64Var(&tail, "tail", 100, "Tail the last N logs")
144148
return cmd
@@ -151,6 +155,7 @@ func newMonitorCmd() *cobra.Command {
151155
RunE: func(cmd *cobra.Command, args []string) error {
152156
panic("not implemented")
153157
},
158+
ValidArgsFunction: ApplicationNames(),
154159
}
155160

156161
}

cmd/arduino-app-cli/completion.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55

66
"github.com/spf13/cobra"
77

8+
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/servicelocator"
89
"github.com/bcmi-labs/orchestrator/cmd/feedback"
10+
"github.com/bcmi-labs/orchestrator/cmd/results"
11+
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
912
)
1013

1114
func newCompletionCommand() *cobra.Command {
@@ -48,3 +51,25 @@ func newCompletionCommand() *cobra.Command {
4851

4952
return completionCmd
5053
}
54+
55+
func ApplicationNames() cobra.CompletionFunc {
56+
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
57+
apps, err := orchestrator.ListApps(cmd.Context(),
58+
servicelocator.GetDockerClient(),
59+
orchestrator.ListAppRequest{
60+
ShowExamples: true,
61+
ShowApps: true,
62+
IncludeNonStandardLocationApps: true,
63+
},
64+
)
65+
if err != nil {
66+
return nil, cobra.ShellCompDirectiveError
67+
}
68+
69+
var res []string
70+
for _, a := range apps.Apps {
71+
res = append(res, results.IdToAlias(a.ID))
72+
}
73+
return res, cobra.ShellCompDirectiveNoFileComp
74+
}
75+
}

0 commit comments

Comments
 (0)