Skip to content

Commit

Permalink
update logic for --frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
tphoney committed Sep 9, 2024
1 parent 4992b4d commit 92402c5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 40 deletions.
7 changes: 2 additions & 5 deletions cmd/changes_get_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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")
}
7 changes: 2 additions & 5 deletions cmd/changes_manual_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.")
Expand Down
8 changes: 2 additions & 6 deletions cmd/changes_submit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.")
Expand Down
17 changes: 7 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
23 changes: 9 additions & 14 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 92402c5

Please sign in to comment.