Skip to content

Commit 924abbd

Browse files
committed
Update shell completion for exec changes
1 parent 15ad21e commit 924abbd

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

cmd/devcontainer/devcontainer.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,25 +210,26 @@ func createExecCommand() *cobra.Command {
210210
Args: cobra.ArbitraryArgs,
211211
DisableFlagsInUseLine: true,
212212
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
213-
// only completing the first arg (devcontainer name)
214-
if len(args) != 0 {
215-
return nil, cobra.ShellCompDirectiveNoFileComp
216-
}
217-
devcontainers, err := devcontainers.ListDevcontainers()
218-
if err != nil {
219-
os.Exit(1)
220-
}
221-
names := []string{}
222-
for _, devcontainer := range devcontainers {
223-
names = append(names, devcontainer.DevcontainerName)
224-
}
225-
sort.Strings(names)
226-
return names, cobra.ShellCompDirectiveNoFileComp
213+
return nil, cobra.ShellCompDirectiveNoFileComp
227214
},
228215
}
229216
cmd.Flags().StringVarP(&argDevcontainerName, "name", "n", "", "name of dev container to exec into")
230217
cmd.Flags().StringVarP(&argDevcontainerPath, "path", "", "", "path containing the dev container to exec into")
231218
cmd.Flags().BoolVarP(&argPromptForDevcontainer, "prompt", "", false, "prompt for the dev container to exec into")
232219
cmd.Flags().StringVarP(&argWorkDir, "work-dir", "", "", "working directory to use in the dev container")
220+
221+
_ = cmd.RegisterFlagCompletionFunc("name", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
222+
devcontainers, err := devcontainers.ListDevcontainers()
223+
if err != nil {
224+
os.Exit(1)
225+
}
226+
names := []string{}
227+
for _, devcontainer := range devcontainers {
228+
names = append(names, devcontainer.DevcontainerName)
229+
}
230+
sort.Strings(names)
231+
return names, cobra.ShellCompDirectiveNoFileComp
232+
233+
})
233234
return cmd
234235
}

0 commit comments

Comments
 (0)