diff --git a/cmd/cluster/clusterCreate.go b/cmd/cluster/clusterCreate.go index 0fb8ce3e..2c76e4d2 100644 --- a/cmd/cluster/clusterCreate.go +++ b/cmd/cluster/clusterCreate.go @@ -272,7 +272,7 @@ func NewCmdClusterCreate() *cobra.Command { ***************/ cmd.Flags().StringVarP(&configFile, "config", "c", "", "Path of a config file to use") - if err := cobra.MarkFlagFilename(cmd.Flags(), "config", "yaml", "yml"); err != nil { + if err := cmd.MarkFlagFilename("config", "yaml", "yml"); err != nil { log.Fatalln("Failed to mark flag 'config' as filename flag") } @@ -387,6 +387,9 @@ func NewCmdClusterCreate() *cobra.Command { cmd.Flags().String("registry-config", "", "Specify path to an extra registries.yaml file") _ = cfgViper.BindPFlag("registries.config", cmd.Flags().Lookup("registry-config")) + if err := cmd.MarkFlagFilename("registry-config", "yaml", "yml"); err != nil { + log.Fatalln("Failed to mark flag 'config' as filename flag") + } /* Subcommands */ diff --git a/cmd/cluster/clusterEdit.go b/cmd/cluster/clusterEdit.go index 5c1c2e75..9743ff72 100644 --- a/cmd/cluster/clusterEdit.go +++ b/cmd/cluster/clusterEdit.go @@ -37,12 +37,12 @@ func NewCmdClusterEdit() *cobra.Command { // create new cobra command cmd := &cobra.Command{ - Use: "edit NAME", + Use: "edit CLUSTER", Short: "[EXPERIMENTAL] Edit cluster(s).", Long: `[EXPERIMENTAL] Edit cluster(s).`, Args: cobra.ExactArgs(1), Aliases: []string{"update"}, - ValidArgsFunction: util.ValidArgsAvailableNodes, + ValidArgsFunction: util.ValidArgsAvailableClusters, Run: func(cmd *cobra.Command, args []string) { existingCluster, changeset := parseEditClusterCmd(cmd, args) diff --git a/cmd/config/configInit.go b/cmd/config/configInit.go index b85b754b..bd5fe831 100644 --- a/cmd/config/configInit.go +++ b/cmd/config/configInit.go @@ -68,6 +68,9 @@ func NewCmdConfigInit() *cobra.Command { } cmd.Flags().StringVarP(&output, "output", "o", "k3d-default.yaml", "Write a default k3d config") + if err := cmd.MarkFlagFilename("output", "yaml", "yml"); err != nil { + log.Fatalf("Failed to mark flag 'output' as filename flag: %v", err) + } cmd.Flags().BoolVarP(&force, "force", "f", false, "Force overwrite of target file") return cmd diff --git a/cmd/config/configMigrate.go b/cmd/config/configMigrate.go index e18b19bc..603fb792 100644 --- a/cmd/config/configMigrate.go +++ b/cmd/config/configMigrate.go @@ -36,8 +36,9 @@ import ( func NewCmdConfigMigrate() *cobra.Command { cmd := &cobra.Command{ - Use: "migrate INPUT OUTPUT", - Args: cobra.RangeArgs(1, 2), + Use: "migrate INPUT [OUTPUT]", + Aliases: []string{"update"}, + Args: cobra.RangeArgs(1, 2), Run: func(cmd *cobra.Command, args []string) { configFile := args[0] diff --git a/cmd/config/configView.go b/cmd/config/configView.go index 658d13b6..8bb50b43 100644 --- a/cmd/config/configView.go +++ b/cmd/config/configView.go @@ -24,7 +24,6 @@ package config import ( "fmt" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -35,9 +34,7 @@ func NewCmdConfigView() *cobra.Command { Use: "view", Aliases: []string{"show"}, Run: func(cmd *cobra.Command, args []string) { - log.Debugln("print config") fmt.Printf("%+v", viper.AllSettings()) - log.Debugln("printed config") }, } return cmd diff --git a/cmd/debug/debug.go b/cmd/debug/debug.go index 19a58b6a..ffbad05f 100644 --- a/cmd/debug/debug.go +++ b/cmd/debug/debug.go @@ -24,6 +24,7 @@ package debug import ( "fmt" + "github.com/rancher/k3d/v4/cmd/util" "github.com/rancher/k3d/v4/pkg/client" "github.com/rancher/k3d/v4/pkg/runtimes" "github.com/rancher/k3d/v4/pkg/types" @@ -67,8 +68,9 @@ func NewCmdDebugLoadbalancer() *cobra.Command { } cmd.AddCommand(&cobra.Command{ - Use: "get-config CLUSTERNAME", - Args: cobra.ExactArgs(1), // cluster name + Use: "get-config CLUSTERNAME", + Args: cobra.ExactArgs(1), // cluster name + ValidArgsFunction: util.ValidArgsAvailableClusters, Run: func(cmd *cobra.Command, args []string) { c, err := client.ClusterGet(cmd.Context(), runtimes.SelectedRuntime, &types.Cluster{Name: args[0]}) if err != nil { diff --git a/cmd/image/image.go b/cmd/image/image.go index 89698839..a9e2aa8a 100644 --- a/cmd/image/image.go +++ b/cmd/image/image.go @@ -31,9 +31,10 @@ func NewCmdImage() *cobra.Command { // create new cobra command cmd := &cobra.Command{ - Use: "image", - Short: "Handle container images.", - Long: `Handle container images.`, + Use: "image", + Aliases: []string{"images"}, + Short: "Handle container images.", + Long: `Handle container images.`, Run: func(cmd *cobra.Command, args []string) { if err := cmd.Help(); err != nil { log.Errorln("Couldn't get help text") diff --git a/cmd/image/imageImport.go b/cmd/image/imageImport.go index ff34345f..705faf16 100644 --- a/cmd/image/imageImport.go +++ b/cmd/image/imageImport.go @@ -56,7 +56,7 @@ That is, 'rancher/k3d-tools' is treated as 'rancher/k3d-tools:latest'. A file ARCHIVE always takes precedence. So if a file './rancher/k3d-tools' exists, k3d will try to import it instead of the IMAGE of the same name.`, - Aliases: []string{"images"}, + Aliases: []string{"load"}, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { images, clusters := parseLoadImageCmd(cmd, args) diff --git a/cmd/node/nodeEdit.go b/cmd/node/nodeEdit.go index e723f43e..ccdbc525 100644 --- a/cmd/node/nodeEdit.go +++ b/cmd/node/nodeEdit.go @@ -36,7 +36,7 @@ func NewCmdNodeEdit() *cobra.Command { // create new cobra command cmd := &cobra.Command{ - Use: "edit NAME", + Use: "edit NODE", Short: "[EXPERIMENTAL] Edit node(s).", Long: `[EXPERIMENTAL] Edit node(s).`, Args: cobra.ExactArgs(1), diff --git a/cmd/node/nodeList.go b/cmd/node/nodeList.go index c4abde01..f1cf1ac1 100644 --- a/cmd/node/nodeList.go +++ b/cmd/node/nodeList.go @@ -46,7 +46,7 @@ func NewCmdNodeList() *cobra.Command { // create new command cmd := &cobra.Command{ - Use: "list [NAME [NAME...]]", + Use: "list [NODE [NODE...]]", Aliases: []string{"ls", "get"}, Short: "List node(s)", Long: `List node(s).`, diff --git a/cmd/node/nodeStart.go b/cmd/node/nodeStart.go index 86506c86..556dd0af 100644 --- a/cmd/node/nodeStart.go +++ b/cmd/node/nodeStart.go @@ -35,7 +35,7 @@ func NewCmdNodeStart() *cobra.Command { // create new command cmd := &cobra.Command{ - Use: "start NAME", // TODO: startNode: allow one or more names or --all + Use: "start NODE", // TODO: startNode: allow one or more names or --all Short: "Start an existing k3d node", Long: `Start an existing k3d node.`, ValidArgsFunction: util.ValidArgsAvailableNodes, diff --git a/cmd/registry/registry.go b/cmd/registry/registry.go index 9ed70a9a..96cba092 100644 --- a/cmd/registry/registry.go +++ b/cmd/registry/registry.go @@ -49,7 +49,6 @@ func NewCmdRegistry() *cobra.Command { cmd.AddCommand(NewCmdRegistryStop()) cmd.AddCommand(NewCmdRegistryDelete()) cmd.AddCommand(NewCmdRegistryList()) - // cmd.AddCommand(NewCmdRegistryConnect()) // TODO: registry connect requires reload capabilities for containerd config // add flags diff --git a/cmd/registry/registryConnect.go b/cmd/registry/registryConnect.go deleted file mode 100644 index 4974a572..00000000 --- a/cmd/registry/registryConnect.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright © 2020-2021 The k3d Author(s) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -package registry - -import "github.com/spf13/cobra" - -// NewCmdRegistryConnect creates a new cobra command -func NewCmdRegistryConnect() *cobra.Command { - return &cobra.Command{} -} diff --git a/cmd/registry/registryDelete.go b/cmd/registry/registryDelete.go index af5e12dd..c2f6f1cc 100644 --- a/cmd/registry/registryDelete.go +++ b/cmd/registry/registryDelete.go @@ -44,6 +44,7 @@ func NewCmdRegistryDelete() *cobra.Command { Use: "delete (NAME | --all)", Short: "Delete registry/registries.", Long: `Delete registry/registries.`, + Aliases: []string{"del", "rm"}, ValidArgsFunction: util.ValidArgsAvailableRegistries, Run: func(cmd *cobra.Command, args []string) { diff --git a/cmd/root.go b/cmd/root.go index 8eb9c9d5..bb5931c8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -233,7 +233,7 @@ var completionFunctions = map[string]func(io.Writer) error{ return nil }, "psh": rootCmd.GenPowerShellCompletion, - "powershell": rootCmd.GenPowerShellCompletion, + "powershell": rootCmd.GenPowerShellCompletionWithDesc, "fish": generateFishCompletion, } @@ -243,8 +243,49 @@ func NewCmdCompletion() *cobra.Command { cmd := &cobra.Command{ Use: "completion SHELL", Short: "Generate completion scripts for [bash, zsh, fish, powershell | psh]", - Long: `Generate completion scripts for [bash, zsh, fish, powershell | psh]`, - Args: cobra.ExactArgs(1), // TODO: NewCmdCompletion: add support for 0 args = auto detection + Long: `To load completions: + +Bash: + + $ source <(k3d completion bash) + + # To load completions for each session, execute once: + # Linux: + $ k3d completion bash > /etc/bash_completion.d/k3d + # macOS: + $ k3d completion bash > /usr/local/etc/bash_completion.d/k3d + +Zsh: + + # If shell completion is not already enabled in your environment, + # you will need to enable it. You can execute the following once: + + $ echo "autoload -U compinit; compinit" >> ~/.zshrc + + # To load completions for each session, execute once: + $ k3d completion zsh > "${fpath[1]}/k3d" + + # You will need to start a new shell for this setup to take effect. + +fish: + + $ k3d completion fish | source + + # To load completions for each session, execute once: + $ k3d completion fish > ~/.config/fish/completions/k3d.fish + +PowerShell: + + PS> k3d completion powershell | Out-String | Invoke-Expression + + # To load completions for every new session, run: + PS> k3d completion powershell > k3d.ps1 + # and source this file from your PowerShell profile. +`, + ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, + ArgAliases: []string{"psh"}, + DisableFlagsInUseLine: true, + Args: cobra.ExactValidArgs(1), Run: func(cmd *cobra.Command, args []string) { if completionFunc, ok := completionFunctions[args[0]]; ok { if err := completionFunc(os.Stdout); err != nil {