From 396523935459dc48c6c38abf6e485bec8f39cee0 Mon Sep 17 00:00:00 2001 From: oleiade Date: Fri, 19 Jul 2024 16:00:23 +0200 Subject: [PATCH] Apply suggestions from code review --- cmd/cloud.go | 10 +++++----- cmd/cloud_login.go | 8 ++++---- cmd/login.go | 8 ++------ cmd/login_cloud.go | 9 ++++----- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/cloud.go b/cmd/cloud.go index add72fdffd3..b04a36865bf 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -390,7 +390,7 @@ To run tests in the cloud, users are now invited to migrate to the "k6 cloud run func exactCloudArgs() cobra.PositionalArgs { return func(_ *cobra.Command, args []string) error { - const baseErrMsg = "the k6 cloud command expects either a subcommand such as `run` or `login`, or " + + const baseErrMsg = `the "k6 cloud" command expects either a subcommand such as "run" or "login", or ` + "a single argument consisting in a path to a script/archive, or the `-` symbol instructing " + "the command to read the test content from stdin" @@ -398,11 +398,11 @@ func exactCloudArgs() cobra.PositionalArgs { return fmt.Errorf(baseErrMsg + "; " + "received no arguments") } - hasSubcommand := len(args) >= 1 && (args[0] == "run" || args[0] == "login") - if !hasSubcommand { + hasSubcommand := args[0] == "run" || args[0] == "login" + if len(args) > 1 && !hasSubcommand { return fmt.Errorf( - baseErrMsg+"; "+"received %d arguments %q, and none of them is a subcommand", - len(args), strings.Join(args, " "), + baseErrMsg+"; "+"received %d arguments %q, and %s is not a valid subcommand", + len(args), strings.Join(args, " "), args[0], ) } diff --git a/cmd/cloud_login.go b/cmd/cloud_login.go index 1981d1913dc..cbba559426f 100644 --- a/cmd/cloud_login.go +++ b/cmd/cloud_login.go @@ -30,16 +30,16 @@ func getCmdCloudLogin(gs *state.GlobalState) *cobra.Command { // loginCloudCommand represents the 'cloud login' command exampleText := getExampleText(gs, ` - # Log in with an email/password. + # Log in with an email/password {{.}} cloud login - # Store a token in k6's persistent configuration. + # Store a token in k6's persistent configuration {{.}} cloud login -t - # Display the stored token. + # Display the stored token {{.}} cloud login -s - # Reset the stored token. + # Reset the stored token {{.}} cloud login -r`[1:]) loginCloudCommand := &cobra.Command{ diff --git a/cmd/login.go b/cmd/login.go index e5fda883901..d0b1c43301d 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -11,16 +11,12 @@ func getCmdLogin(gs *state.GlobalState) *cobra.Command { loginCmd := &cobra.Command{ Use: "login", Short: "Authenticate with a service", - Long: `[deprecation notice] -This command is deprecated and will be removed in a future release. Please use the "k6 cloud login" command instead. - -Authenticate with a service. + Long: `Authenticate with a service. Logging into a service changes the default when just "-o [type]" is passed with no parameters, you can always override the stored credentials by passing some on the commandline.`, - Deprecated: `This command is deprecated and will be removed in a future release. -Please use the "k6 cloud login" command instead. + Deprecated: `and will be removed in a future release. Please use the "k6 cloud login" command instead. `, RunE: func(cmd *cobra.Command, _ []string) error { return cmd.Usage() diff --git a/cmd/login_cloud.go b/cmd/login_cloud.go index 6440c63486f..0aadf7fb749 100644 --- a/cmd/login_cloud.go +++ b/cmd/login_cloud.go @@ -33,15 +33,14 @@ func getCmdLoginCloud(gs *state.GlobalState) *cobra.Command { loginCloudCommand := &cobra.Command{ Use: "cloud", Short: "Authenticate with k6 Cloud", - Long: `[deprecation notice] -This command is deprecated and will be removed in a future release. Please use the -"k6 cloud login" command instead. - -Authenticate with Grafana Cloud k6. + Long: `Authenticate with Grafana Cloud k6. This will set the default token used when just "k6 run -o cloud" is passed.`, Example: exampleText, Args: cobra.NoArgs, + Deprecated: `and will be removed in a future release. +Please use the "k6 cloud login" command instead. +`, RunE: func(cmd *cobra.Command, _ []string) error { currentDiskConf, err := readDiskConfig(gs) if err != nil {