diff --git a/cmd/incus/file.go b/cmd/incus/file.go index 1d623c8c3f9..664ba09ca06 100644 --- a/cmd/incus/file.go +++ b/cmd/incus/file.go @@ -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 } @@ -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 } @@ -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 } @@ -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 }