Skip to content

Commit

Permalink
lxc: Add instance completions to lxc file subcommands
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Oct 2, 2024
1 parent f617c7f commit bd9aeb7
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions lxc/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ type cmdFileCreate struct {
global *cmdGlobal
file *cmdFile

flagForce bool
flagType string
flagForce bool
flagType string
}

// Command returns the cobra command for `file create`.
Expand All @@ -148,6 +148,14 @@ lxc file create --type=symlink foo/bar baz
cmd.Flags().StringVar(&c.flagType, "type", "file", i18n.G("The type to create (file, symlink, or directory)")+"``")
cmd.RunE = c.run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return c.global.cmpInstances(toComplete)
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down Expand Up @@ -315,6 +323,14 @@ func (c *cmdFileDelete) command() *cobra.Command {

cmd.RunE = c.run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return c.global.cmpInstances(toComplete)
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down Expand Up @@ -364,6 +380,14 @@ func (c *cmdFileEdit) command() *cobra.Command {

cmd.RunE = c.run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return c.global.cmpInstances(toComplete)
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down Expand Up @@ -439,6 +463,14 @@ func (c *cmdFilePull) command() *cobra.Command {
cmd.Flags().BoolVarP(&c.file.flagRecursive, "recursive", "r", false, i18n.G("Recursively transfer files"))
cmd.RunE = c.run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return c.global.cmpInstances(toComplete)
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down Expand Up @@ -1184,6 +1216,14 @@ func (c *cmdFileMount) command() *cobra.Command {
cmd.Flags().BoolVar(&c.flagAuthNone, "no-auth", false, i18n.G("Disable authentication when using SSH SFTP listener"))
cmd.Flags().StringVar(&c.flagAuthUser, "auth-user", "", i18n.G("Set authentication user when using SSH SFTP listener"))

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return c.global.cmpInstances(toComplete)
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down

0 comments on commit bd9aeb7

Please sign in to comment.