Add dryRunOptionalEnabled and collapse duplicated flag guards#355
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up cleanup to the dry-run generalization series. Several option parsers are shared with callers that do not register the
--dry-runflag, so each guarded the lookup withif cmd.Flags().Lookup(dryRunFlagName) != nil { ... }before reading it. This extracts that repeated pattern into a single helper.Changes
cmd/dry_run.go— adddryRunOptionalEnabled(cmd): returns false when the flag isn't registered, else delegates todryRunEnabled.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.