Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func dryRunEnabled(cmd *cobra.Command) (bool, error) {
return cmd.Flags().GetBool(dryRunFlagName)
}

// dryRunOptionalEnabled returns the dry-run flag state, or false when the flag
// is not registered. Option parsers shared with callers that do not register
// --dry-run use this instead of dryRunEnabled to avoid a missing-flag error.
func dryRunOptionalEnabled(cmd *cobra.Command) (bool, error) {
if cmd == nil || cmd.Flags().Lookup(dryRunFlagName) == nil {
return false, nil
}
return dryRunEnabled(cmd)
}

// Dry-run JSON results use status "planned" and include dry_run=true in the
// result input. They do not preserve the real mutation status, because no
// mutation happened.
Expand Down
9 changes: 3 additions & 6 deletions cmd/relocation_if_exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ func parseRelocationOptions(cmd *cobra.Command) (relocationOptions, error) {
if err != nil {
return relocationOptions{}, err
}
dryRun := false
// Some tests and callers use relocation parsing without registering --dry-run.
if cmd != nil && cmd.Flags().Lookup(dryRunFlagName) != nil {
dryRun, err = dryRunEnabled(cmd)
if err != nil {
return relocationOptions{}, err
}
dryRun, err := dryRunOptionalEnabled(cmd)
if err != nil {
return relocationOptions{}, err
}
return relocationOptions{ifExists: ifExists, dryRun: dryRun}, nil
}
Expand Down
10 changes: 4 additions & 6 deletions cmd/share_link_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,11 @@ func parseShareLinkCreateOptions(cmd *cobra.Command) (shareLinkCreateOptions, er
return opts, err
}
opts.password = password
if cmd.Flags().Lookup(dryRunFlagName) != nil {
dryRun, err := dryRunEnabled(cmd)
if err != nil {
return opts, err
}
opts.dryRun = dryRun
dryRun, err := dryRunOptionalEnabled(cmd)
if err != nil {
return opts, err
}
opts.dryRun = dryRun

if opts.expires != nil && opts.removeExpiration {
return opts, invalidArgumentsErrorWithDetails("`--expires` and `--remove-expiration` cannot be used together", flagsErrorDetails("expires", "remove-expiration"))
Expand Down
10 changes: 4 additions & 6 deletions cmd/share_link_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ func shareLinkRevokeOperationResults(revoked []shareLinkRevokeResult, dryRun boo
func parseShareLinkRevokeOptions(cmd *cobra.Command, args []string) (shareLinkRevokeOptions, error) {
var opts shareLinkRevokeOptions

if cmd.Flags().Lookup(dryRunFlagName) != nil {
dryRun, err := dryRunEnabled(cmd)
if err != nil {
return opts, err
}
opts.dryRun = dryRun
dryRun, err := dryRunOptionalEnabled(cmd)
if err != nil {
return opts, err
}
opts.dryRun = dryRun

if !localFlagChanged(cmd, "path") {
return opts, nil
Expand Down
9 changes: 3 additions & 6 deletions cmd/share_link_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,9 @@ func parseShareLinkUpdateOptions(cmd *cobra.Command) (shareLinkUpdateOptions, er
if err != nil {
return shareLinkUpdateOptions{}, err
}
var dryRun bool
if cmd.Flags().Lookup(dryRunFlagName) != nil {
dryRun, err = dryRunEnabled(cmd)
if err != nil {
return shareLinkUpdateOptions{}, err
}
dryRun, err := dryRunOptionalEnabled(cmd)
if err != nil {
return shareLinkUpdateOptions{}, err
}

if expiresChanged && removeExpiration {
Expand Down
Loading