From 3c1f4157bf6f9cf692e0b56f49b0f785bafdb42f Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Fri, 25 Aug 2023 18:45:22 +0200 Subject: [PATCH 1/3] Include positional arguments help for profile command --- cmd/profiles.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/profiles.go b/cmd/profiles.go index 6960e0735f..013a5bc720 100644 --- a/cmd/profiles.go +++ b/cmd/profiles.go @@ -41,8 +41,9 @@ User profiles can be configured with a "config.yml" file in the profile director } profileNewCommand := &cobra.Command{ - Use: "create", + Use: "create [profile]", Short: "Create a new profile", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { @@ -75,8 +76,9 @@ User profiles can be configured with a "config.yml" file in the profile director profileNewCommand.Flags().String(cobraext.ProfileFromFlagName, "", cobraext.ProfileFromFlagDescription) profileDeleteCommand := &cobra.Command{ - Use: "delete", + Use: "delete [profile]", Short: "Delete a profile", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("delete requires an argument") @@ -153,8 +155,9 @@ User profiles can be configured with a "config.yml" file in the profile director profileListCommand.Flags().String(cobraext.ProfileFormatFlagName, tableFormat, cobraext.ProfileFormatFlagDescription) profileUseCommand := &cobra.Command{ - Use: "use", + Use: "use [profile]", Short: "Sets the profile to use when no other is specified", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("use requires an argument") From a061da43f513dd41bc3e7eae9637c021a9dc9e29 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Mon, 28 Aug 2023 12:44:13 +0200 Subject: [PATCH 2/3] Remove safeguards about args length --- cmd/profiles.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cmd/profiles.go b/cmd/profiles.go index 013a5bc720..408f55bed1 100644 --- a/cmd/profiles.go +++ b/cmd/profiles.go @@ -6,7 +6,6 @@ package cmd import ( "encoding/json" - "errors" "fmt" "os" "time" @@ -45,10 +44,6 @@ User profiles can be configured with a "config.yml" file in the profile director Short: "Create a new profile", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - - if len(args) == 0 { - return errors.New("create requires an argument") - } newProfileName := args[0] fromName, err := cmd.Flags().GetString(cobraext.ProfileFromFlagName) @@ -80,9 +75,6 @@ User profiles can be configured with a "config.yml" file in the profile director Short: "Delete a profile", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errors.New("delete requires an argument") - } profileName := args[0] config, err := install.Configuration() @@ -159,9 +151,6 @@ User profiles can be configured with a "config.yml" file in the profile director Short: "Sets the profile to use when no other is specified", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errors.New("use requires an argument") - } profileName := args[0] _, err := profile.LoadProfile(profileName) From 4aee9b9af35e337ea3be5a3bc0b072bebb31e66a Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Mon, 28 Aug 2023 12:44:26 +0200 Subject: [PATCH 3/3] Set no args for list subcommand --- cmd/profiles.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/profiles.go b/cmd/profiles.go index 408f55bed1..48594c34e8 100644 --- a/cmd/profiles.go +++ b/cmd/profiles.go @@ -111,6 +111,7 @@ User profiles can be configured with a "config.yml" file in the profile director profileListCommand := &cobra.Command{ Use: "list", Short: "List available profiles", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { loc, err := locations.NewLocationManager() if err != nil {