-
Notifications
You must be signed in to change notification settings - Fork 3
Add safe dry-run previews for mutations #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func TestInitConfigBindsFlagsWithoutConfigFile(t *testing.T) { | ||
| viper.Reset() | ||
| t.Cleanup(viper.Reset) | ||
| t.Setenv("CONE_CONFIG_PATH", t.TempDir()) | ||
|
|
||
| cmd := &cobra.Command{} | ||
|
|
||
| cmd.PersistentFlags().Bool("debug", false, "") | ||
| if err := initConfig(cmd); err != nil { | ||
| t.Fatalf("initConfig: %v", err) | ||
| } | ||
| if err := cmd.ParseFlags([]string{"--debug"}); err != nil { | ||
| t.Fatalf("ParseFlags: %v", err) | ||
| } | ||
| if !viper.GetBool("debug") { | ||
| t.Fatal("--debug was not bound when no config file exists") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,9 @@ func runCli(ctx context.Context) int { | |
| Short: "Cone interacts with the ConductorOne API to manage access to entitlements.", | ||
| Version: version, | ||
| PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
| if dryRunEnabled(cmd) && !dryRunSupported(cmd) { | ||
| return fmt.Errorf("--dry-run is not supported by %q", cmd.CommandPath()) | ||
| } | ||
| cmd.SetContext(ctx) | ||
| return nil | ||
| }, | ||
|
|
@@ -58,6 +61,7 @@ func runCli(ctx context.Context) int { | |
| cliCmd.PersistentFlags().StringP("output", "o", "table", "Output format. Valid values: table, json, json-pretty, wide.") | ||
| cliCmd.PersistentFlags().Bool("debug", false, "Enable HTTP debug logging") | ||
| cliCmd.PersistentFlags().String("log-level", "", "Set log level (debug, info, warn, error)") | ||
| cliCmd.PersistentFlags().Bool(dryRunFlag, false, "Preview supported mutations without sending them") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: as a root persistent flag, |
||
|
|
||
| err := initConfig(cliCmd) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion:
previewMutationsis documented as returning "true when the caller must return without making a change", and the other five call sites useif previewMutations(...) { return nil }. Here (and inrunDropat line 343) the return value is discarded and the gate is duplicated as a separatedryRunEnabled(cmd)check, so any future change topreviewMutations' gating would silently diverge in exactly the two commands that create tasks.if previewMutations(...) { return nil, nil }keeps a single source of truth.