Repository navigation
Exit non-zero when a run fails, is aborted, or cannot parse its arguments [patch] - #170
Merged
Merged
Conversation
…ents [patch] Main and every verb returned void, so the process exited 0 for a missing directory, an abort, failed deletions and unknown options alike. Main now returns the verb's exit code through MapResult: 0 on success (and for --help/--version), 1 when the root is missing or not a directory, the user aborts at a prompt, or Deduplicate finishes with deletion errors, and 2 when the arguments cannot be parsed. FileScanner.TryScanForFiles tells a root that could not be scanned apart from an empty one. Fixes #144 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U5RBnMaTjZdMDRNttjeZ3u
…the copied pipeline SonarCloud failed the PR on 10.5% duplication on new code: the new return-value lines sat inside the scan pipeline that Scan, DryRun, Stats and Deduplicate each carry a copy of (#157). BaseVerb<T>.Run now checks the root with FileScanner.IsScannableDirectory before the verb runs and returns the verb's ExitCode, which Deduplicate sets when the user declines or a deletion fails. Scan, DryRun and Stats go back to their main versions. The exit-code tests share their console capture and assertions instead of repeating them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U5RBnMaTjZdMDRNttjeZ3u
|
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.



Fixes #144
Before:
Mainand every verb returnedvoid, so the process exited 0 for a missing directory, an abort, failed deletions and unknown options.Deduplicate -p /data && echo donereported success even when nothing was deleted.After, measured against the built dll:
Scan -p /nonexistentScan -p <a file>Scan --nope--helpScan -p <dir>echo n | Deduplicate -p <dir with duplicates>How:
Mainreturnsintand goes throughProgram.Run(parser, args), which usesParseArguments(...).MapResult(...). A parse failure returns 2. Asking for help or the version returns 0.BaseVerb.Run()returns the exit code, andICommand.Execute(the menu) discards it.BaseVerb<T>.Runreturns 1 in two cases:FileScanner.IsScannableDirectorybefore the verb runsOtherwise it returns the verb's
ExitCode, which starts at 0.Deduplicatesets it to 1 when the user declines or a deletion fails.Menuopts out of the root check.Scan, DryRun and Stats are unchanged. Putting the exit code in their bodies added lines inside the scan pipeline that all four verbs copy (Scan, DryRun, Deduplicate and Stats each copy the path prompt and the scan→hash→group pipeline, so every fix to that path must be made four times #157), and SonarCloud failed the first push on 10.5% duplication on new code.
ExitCodeTestscovers each case, including a real command line throughProgram.Run. WithBaseVerb<T>.RunandMainforced back to returning 0, six of them fail.The deletion-failure test is inconclusive as root, the same as the existing
ACopyThatCannotBeDeletedIsReportedAndTheRunCarriesOn. I ran both asnobodyand both passed.Not covered: an unknown verb (
FileDeduplicator Nope) still falls through to the defaultMenuverb rather than exiting 2. That's the path #161 is about.This branches from main, separately from #169 (for #145). Both touch
BaseVerb, so whichever merges second may need a small merge.Tests: 77 total, 74 passed, 3 skipped (the permission-staging tests, which can't stage the failure as root).
🤖 Generated with Claude Code
https://claude.ai/code/session_01U5RBnMaTjZdMDRNttjeZ3u