Skip to content

Add dryRunOptionalEnabled and collapse duplicated flag guards#355

Merged
AndreyVMarkelov merged 1 commit into
masterfrom
feature/dry-run-optional-enabled
Jul 11, 2026
Merged

Add dryRunOptionalEnabled and collapse duplicated flag guards#355
AndreyVMarkelov merged 1 commit into
masterfrom
feature/dry-run-optional-enabled

Conversation

@AndreyVMarkelov

@AndreyVMarkelov AndreyVMarkelov commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up cleanup to the dry-run generalization series. Several option parsers are shared with callers that do not register the --dry-run flag, so each guarded the lookup with if cmd.Flags().Lookup(dryRunFlagName) != nil { ... } before reading it. This extracts that repeated pattern into a single helper.

Changes

  • cmd/dry_run.go — add dryRunOptionalEnabled(cmd): returns false when the flag isn't registered, else delegates to dryRunEnabled.
  • cmd/share_link_create.go, cmd/share_link_update.go, cmd/share_link_revoke.go, cmd/relocation_if_exists.go — each drops its inline guard for a call to the helper.

Why only these four

mkdir/restore/rm/put call dryRunEnabled(cmd) directly and are left as-is — they always register the flag, so routing them through the optional helper would wrongly imply it might be absent. The helper is only for parsers shared with non-dry-run callers.

Several option parsers are shared with callers that do not register the
--dry-run flag, so each guarded the lookup with

    if cmd.Flags().Lookup(dryRunFlagName) != nil { ... }

before reading it. Extract that pattern into dryRunOptionalEnabled,
which returns false when the flag is absent, and use it in
share-link create/update/revoke and the relocation (cp/mv) parser.

Behavior is unchanged: verified byte-for-byte against the pre-refactor
binary for share-link create and cp dry-run output, and the relocation
no-flag parser paths still pass.
@AndreyVMarkelov AndreyVMarkelov merged commit b292561 into master Jul 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant