cleanup completion functions

pull/682/head v5.0.0-dev.0
iwilltry42 3 years ago
parent 581378feb0
commit b94a057d9a
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 5
      cmd/cluster/clusterCreate.go
  2. 4
      cmd/cluster/clusterEdit.go
  3. 3
      cmd/config/configInit.go
  4. 5
      cmd/config/configMigrate.go
  5. 3
      cmd/config/configView.go
  6. 6
      cmd/debug/debug.go
  7. 7
      cmd/image/image.go
  8. 2
      cmd/image/imageImport.go
  9. 2
      cmd/node/nodeEdit.go
  10. 2
      cmd/node/nodeList.go
  11. 2
      cmd/node/nodeStart.go
  12. 1
      cmd/registry/registry.go
  13. 29
      cmd/registry/registryConnect.go
  14. 1
      cmd/registry/registryDelete.go
  15. 47
      cmd/root.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 */

@ -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)

@ -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

@ -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]

@ -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

@ -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 {

@ -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")

@ -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)

@ -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),

@ -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).`,

@ -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,

@ -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

@ -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{}
}

@ -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) {

@ -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 {

Loading…
Cancel
Save