diff --git a/cmd/changes_get_change.go b/cmd/changes_get_change.go index 2021833f..fb176e9f 100644 --- a/cmd/changes_get_change.go +++ b/cmd/changes_get_change.go @@ -43,10 +43,7 @@ const assetVersion = "17c7fd2c365d4f4cdd8e414ca5148f825fa4febd" func GetChange(cmd *cobra.Command, args []string) error { ctx := cmd.Context() - app, err := getAppUrl(viper.GetString("frontend"), viper.GetString("app")) - if err != nil { - log.Fatalf("Error: %v", err) - } + app := getAppUrl(viper.GetString("frontend"), viper.GetString("app")) riskLevels := []sdp.Risk_Severity{} for _, level := range viper.GetStringSlice("risk-levels") { @@ -397,7 +394,7 @@ func init() { getChangeCmd.PersistentFlags().String("status", "", "The expected status of the change. Use this with --ticket-link. Allowed values: CHANGE_STATUS_UNSPECIFIED, CHANGE_STATUS_DEFINING, CHANGE_STATUS_HAPPENING, CHANGE_STATUS_PROCESSING, CHANGE_STATUS_DONE") getChangeCmd.PersistentFlags().String("frontend", "", "The frontend base URL") - _ = submitPlanCmd.PersistentFlags().MarkDeprecated("frontend", "This flag is no longer used and will be removed in a future release. Use the '--app' flag instead.") + _ = submitPlanCmd.PersistentFlags().MarkDeprecated("frontend", "This flag is no longer used and will be removed in a future release. Use the '--app' flag instead.") // MarkDeprecated only errors if the flag doesn't exist, we fall back to using app getChangeCmd.PersistentFlags().String("format", "json", "How to render the change. Possible values: json, markdown") getChangeCmd.PersistentFlags().StringSlice("risk-levels", []string{"high", "medium", "low"}, "Only show changes with the specified risk levels. Allowed values: high, medium, low") } diff --git a/cmd/changes_manual_change.go b/cmd/changes_manual_change.go index 5306e881..7dc3111a 100644 --- a/cmd/changes_manual_change.go +++ b/cmd/changes_manual_change.go @@ -26,10 +26,7 @@ var manualChangeCmd = &cobra.Command{ func ManualChange(cmd *cobra.Command, args []string) error { ctx := cmd.Context() - app, err := getAppUrl(viper.GetString("frontend"), viper.GetString("app")) - if err != nil { - log.Fatalf("Error: %v", err) - } + app := getAppUrl(viper.GetString("frontend"), viper.GetString("app")) method, err := methodFromString(viper.GetString("query-method")) if err != nil { @@ -199,7 +196,7 @@ func init() { changesCmd.AddCommand(manualChangeCmd) addAPIFlags(manualChangeCmd) manualChangeCmd.PersistentFlags().String("frontend", "", "The frontend base URL") - _ = submitPlanCmd.PersistentFlags().MarkDeprecated("frontend", "This flag is no longer used and will be removed in a future release. Use the '--app' flag instead.") + _ = submitPlanCmd.PersistentFlags().MarkDeprecated("frontend", "This flag is no longer used and will be removed in a future release. Use the '--app' flag instead.") // MarkDeprecated only errors if the flag doesn't exist, we fall back to using app manualChangeCmd.PersistentFlags().String("title", "", "Short title for this change.") manualChangeCmd.PersistentFlags().String("description", "", "Quick description of the change.") manualChangeCmd.PersistentFlags().String("ticket-link", "*", "Link to the ticket for this change.") diff --git a/cmd/changes_submit_plan.go b/cmd/changes_submit_plan.go index 35f605bd..d78478da 100644 --- a/cmd/changes_submit_plan.go +++ b/cmd/changes_submit_plan.go @@ -143,10 +143,7 @@ func tryLoadText(ctx context.Context, fileName string) string { func SubmitPlan(cmd *cobra.Command, args []string) error { ctx := cmd.Context() - app, err := getAppUrl(viper.GetString("frontend"), viper.GetString("app")) - if err != nil { - log.Fatalf("Error: %v", err) - } + app := getAppUrl(viper.GetString("frontend"), viper.GetString("app")) ctx, oi, _, err := login(ctx, cmd, []string{"changes:write"}) if err != nil { @@ -343,8 +340,7 @@ func init() { addAPIFlags(submitPlanCmd) submitPlanCmd.PersistentFlags().String("frontend", "", "The frontend base URL") - _ = submitPlanCmd.PersistentFlags().MarkDeprecated("frontend", "This flag is no longer used and will be removed in a future release. Use the '--app' flag instead.") - + _ = submitPlanCmd.PersistentFlags().MarkDeprecated("frontend", "This flag is no longer used and will be removed in a future release. Use the '--app' flag instead.") // MarkDeprecated only errors if the flag doesn't exist, we fall back to using app submitPlanCmd.PersistentFlags().String("title", "", "Short title for this change. If this is not specified, overmind will try to come up with one for you.") submitPlanCmd.PersistentFlags().String("description", "", "Quick description of the change.") submitPlanCmd.PersistentFlags().String("ticket-link", "*", "Link to the ticket for this change. Usually this would be the link to something like the pull request, since the CLI uses this as a unique identifier for the change, meaning that multiple runs with the same ticket link will update the same change.") diff --git a/cmd/root.go b/cmd/root.go index fdb65dd7..c00d4122 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -590,18 +590,15 @@ func login(ctx context.Context, cmd *cobra.Command, scopes []string) (context.Co return ctx, oi, token, nil } -func getAppUrl(frontend, app string) (string, error) { +func getAppUrl(frontend, app string) string { if frontend == "" && app == "" { - return "", fmt.Errorf("'--app' flag must be set") + return "https://app.overmind.tech" } - if frontend != "" && app != "" { - log.WithError(fmt.Errorf("both '--frontend' and '--app' are set, using --frontend %q. Please only Use '--app'", frontend)).Warn("both '--frontend' and '--app' are set") - return frontend, nil + if frontend != "" && app == "" { + return frontend } - // if frontend is set and app is not set, set app to frontend - if frontend != "" { - return frontend, nil - } else { - return app, nil + if frontend != "" && app != "" { + log.Warnf("Both --frontend and --app are set, but they are different. Using --app: %v", app) } + return app } diff --git a/cmd/root_test.go b/cmd/root_test.go index 81d791fe..e39e5141 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -91,24 +91,19 @@ func Test_getAppUrl(t *testing.T) { app string } tests := []struct { - name string - args args - want string - wantErr bool + name string + args args + want string }{ - {name: "empty", args: args{frontend: "", app: ""}, want: "", wantErr: true}, - {name: "empty app", args: args{frontend: "https://app.overmind.tech/", app: ""}, want: "https://app.overmind.tech/", wantErr: false}, - {name: "empty frontend", args: args{frontend: "", app: "https://app.overmind.tech/"}, want: "https://app.overmind.tech/", wantErr: false}, - {name: "same", args: args{frontend: "https://app.overmind.tech/", app: "https://app.overmind.tech/"}, want: "https://app.overmind.tech/", wantErr: false}, - {name: "different", args: args{frontend: "https://app.overmind.tech/", app: "https://app.overmind.tech/changes/123"}, want: "https://app.overmind.tech/", wantErr: false}, + {name: "empty", args: args{frontend: "", app: ""}, want: "https://app.overmind.tech"}, + {name: "empty app", args: args{frontend: "https://app.overmind.tech", app: ""}, want: "https://app.overmind.tech"}, + {name: "empty frontend", args: args{frontend: "", app: "https://app.overmind.tech"}, want: "https://app.overmind.tech"}, + {name: "same", args: args{frontend: "https://app.overmind.tech", app: "https://app.overmind.tech"}, want: "https://app.overmind.tech"}, + {name: "different", args: args{frontend: "https://app.overmind.tech", app: "https://app.overmind.tech/changes/123"}, want: "https://app.overmind.tech/changes/123"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := getAppUrl(tt.args.frontend, tt.args.app) - if (err != nil) != tt.wantErr { - t.Errorf("getAppUrl() error = %v, wantErr %v", err, tt.wantErr) - return - } + got := getAppUrl(tt.args.frontend, tt.args.app) if got != tt.want { t.Errorf("getAppUrl() = %v, want %v", got, tt.want) }