From 853634a97fcdb97d8827dc18626002341f11df98 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Thu, 3 Mar 2022 09:18:49 +0900 Subject: [PATCH] Make error if arguments are given for subcommands that require no arguments. --- cmd/delete.go | 1 + cmd/kubernetes.go | 4 ++++ cmd/list.go | 1 + cmd/nerdctl.go | 1 + cmd/start.go | 1 + cmd/status.go | 1 + cmd/stop.go | 1 + cmd/version.go | 1 + 8 files changed, 11 insertions(+) diff --git a/cmd/delete.go b/cmd/delete.go index 5ef007865..fbd3f925b 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -21,6 +21,7 @@ Use with caution. This deletes everything and a startup afterwards is like the initial startup of Colima. If you simply want to reset the Kubernetes cluster, run 'colima kubernetes reset'.`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { if !deleteCmdArgs.force { y := cli.Prompt("are you sure you want to delete " + config.Profile().DisplayName + " and all settings") diff --git a/cmd/kubernetes.go b/cmd/kubernetes.go index 3b17b972d..246d0f677 100644 --- a/cmd/kubernetes.go +++ b/cmd/kubernetes.go @@ -34,6 +34,7 @@ var kubernetesStartCmd = &cobra.Command{ Use: "start", Short: "start the Kubernetes cluster", Long: `Start the Kubernetes cluster.`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { app := newApp() k, err := app.Kubernetes() @@ -54,6 +55,7 @@ var kubernetesStopCmd = &cobra.Command{ Use: "stop", Short: "stop the Kubernetes cluster", Long: `Stop the Kubernetes cluster.`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { app := newApp() k, err := app.Kubernetes() @@ -73,6 +75,7 @@ var kubernetesDeleteCmd = &cobra.Command{ Use: "delete", Short: "delete the Kubernetes cluster", Long: `Delete the Kubernetes cluster.`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { app := newApp() k, err := app.Kubernetes() @@ -97,6 +100,7 @@ This resets the Kubernetes cluster and all Kubernetes objects will be deleted. The Kubernetes images are cached making the startup (after reset) much faster.`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { app := newApp() k, err := app.Kubernetes() diff --git a/cmd/list.go b/cmd/list.go index 4570cdef0..a564bfb0e 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -19,6 +19,7 @@ var listCmd = &cobra.Command{ Long: `List all created instances. A new instance can be created during 'colima start' by specifying the '--profile' flag.`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { instances, err := lima.Instances() if err != nil { diff --git a/cmd/nerdctl.go b/cmd/nerdctl.go index b830fcafc..b6f6a53ab 100644 --- a/cmd/nerdctl.go +++ b/cmd/nerdctl.go @@ -54,6 +54,7 @@ var nerdctlLinkFunc = func() *cobra.Command { Use: "install", Short: "install nerdctl alias script on the host", Long: `Install nerdctl alias script on the host. The script will be installed at ` + nerdctlDefaultInstallPath + `.`, + Args: cobra.NoArgs, PreRun: func(cmd *cobra.Command, args []string) { // check if /usr/local/bin is writeable and no need for sudo diff --git a/cmd/start.go b/cmd/start.go index 50bc36274..e558c7f6d 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -28,6 +28,7 @@ The --runtime, --disk and --arch flags are only used on initial start and ignore " colima start --cpu 4 --memory 8 --disk 100\n" + " colima start --arch aarch64\n" + " colima start --dns 1.1.1.1 --dns 8.8.8.8", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return newApp().Start(startCmdArgs.Config) }, diff --git a/cmd/status.go b/cmd/status.go index 41e4bbc8f..4729146ff 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -10,6 +10,7 @@ var statusCmd = &cobra.Command{ Use: "status", Short: "show the status of Colima", Long: `Show the status of Colima`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return newApp().Status() }, diff --git a/cmd/stop.go b/cmd/stop.go index 9f0d9f359..b13d16011 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -13,6 +13,7 @@ var stopCmd = &cobra.Command{ The state of the VM is persisted at stop. A start afterwards should return it back to its previous state.`, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return newApp().Stop() }, diff --git a/cmd/version.go b/cmd/version.go index 1fecbbea2..118b58d4f 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -14,6 +14,7 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "print the version of Colima", Long: `Print the version of Colima`, + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { version := config.AppVersion() fmt.Println(config.AppName, "version", version.Version)