summaryrefslogtreecommitdiffstats
path: root/commands/config.go
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2024-04-07 20:33:17 +0000
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-04-11 15:34:26 +0200
commita67650b6f764d201fde22b1bc3c06b923fdc5438 (patch)
tree698bdb49baf78317ad506fcf8642a0f6da883543 /commands/config.go
parent2a060b37a32c3831ece2203b8b5451adb3c787af (diff)
completion: Improve existing argument completions, add many more
Do not offer filenames to arguments not taking one, complete arguments of options taking resource kinds, directory names, --logLevel, release --step, config and new --format. As an internal refactoring, use higher level functions to set flag completions. SetAnnotation works, but is more verbose than alternatives, and uses bash specific wording. While at it, move setting completions next to flag definitions consistently. Remove superfluous --destination completer setting, which is already set elsewhere.
Diffstat (limited to 'commands/config.go')
-rw-r--r--commands/config.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/commands/config.go b/commands/config.go
index dfe54cba2..adf6bbe2b 100644
--- a/commands/config.go
+++ b/commands/config.go
@@ -28,6 +28,7 @@ import (
"github.com/gohugoio/hugo/modules"
"github.com/gohugoio/hugo/parser"
"github.com/gohugoio/hugo/parser/metadecoders"
+ "github.com/spf13/cobra"
)
// newConfigCommand creates a new config command and its subcommands.
@@ -112,7 +113,9 @@ func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
cmd.Short = "Print the site configuration"
cmd.Long = `Print the site configuration, both default and custom settings.`
cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)")
+ _ = cmd.RegisterFlagCompletionFunc("format", cobra.FixedCompletions([]string{"toml", "yaml", "json"}, cobra.ShellCompDirectiveNoFileComp))
cmd.Flags().StringVar(&c.lang, "lang", "", "the language to display config for. Defaults to the first language defined.")
+ _ = cmd.RegisterFlagCompletionFunc("lang", cobra.NoFileCompletions)
applyLocalFlagsBuildConfig(cmd, c.r)
return nil
@@ -223,6 +226,7 @@ func (c *configMountsCommand) Init(cd *simplecobra.Commandeer) error {
c.r = cd.Root.Command.(*rootCommand)
cmd := cd.CobraCommand
cmd.Short = "Print the configured file mounts"
+ cmd.ValidArgsFunction = cobra.NoFileCompletions
applyLocalFlagsBuildConfig(cmd, c.r)
return nil
}