Skip to content

Commit

Permalink
Merge pull request #1453 from montag451/file-comp
Browse files Browse the repository at this point in the history
incus: Improve completion for some file sub-commmands
  • Loading branch information
stgraber authored Dec 3, 2024
2 parents 5ab0c6e + 6517801 commit 4441e6c
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion cmd/incus/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,17 @@ incus file create --type=symlink foo/bar baz
cmd.Flags().IntVar(&c.file.flagUID, "uid", -1, i18n.G("Set the file's uid on create")+"``")
cmd.Flags().StringVar(&c.file.flagMode, "mode", "", i18n.G("Set the file's perms on create")+"``")
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.cmpFiles(toComplete, false)
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down Expand Up @@ -326,6 +335,10 @@ func (c *cmdFileDelete) Command() *cobra.Command {

cmd.RunE = c.Run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return c.global.cmpFiles(toComplete, false)
}

return cmd
}

Expand Down Expand Up @@ -402,6 +415,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.cmpFiles(toComplete, false)
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down Expand Up @@ -1270,11 +1291,24 @@ func (c *cmdFileMount) Command() *cobra.Command {
`incus file mount foo/root fooroot
To mount /root from the instance foo onto the local fooroot directory.`))

cmd.RunE = c.Run
cmd.Flags().StringVar(&c.flagListen, "listen", "", i18n.G("Setup SSH SFTP listener on address:port instead of mounting"))
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.RunE = c.Run

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

if len(args) == 1 {
return nil, cobra.ShellCompDirectiveDefault
}

return nil, cobra.ShellCompDirectiveNoFileComp
}

return cmd
}

Expand Down

0 comments on commit 4441e6c

Please sign in to comment.