Skip to content
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

feat(cli): Dry run #156

Merged
merged 8 commits into from
Nov 3, 2024
Merged

feat(cli): Dry run #156

merged 8 commits into from
Nov 3, 2024

Conversation

alexpovel
Copy link
Owner

This change adds a new flag --dry-run that when
given, prevents otherwise destructive file
overwrite operations and instead prints a rich
diff. The diff contains names of files which would be modified, and a git-like diff of what
modifications would be made.

The diff is human-readable, and not designed to be easily machine-readable.

The change leverages the similar crate, on which we transitively depended on already anyway.

Closes #152.

@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2024

Codecov Report

Attention: Patch coverage is 95.65217% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.78%. Comparing base (3beac24) to head (4932c6d).

Files with missing lines Patch % Lines
src/main.rs 94.11% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #156      +/-   ##
==========================================
+ Coverage   86.72%   86.78%   +0.06%     
==========================================
  Files          32       33       +1     
  Lines        1876     1900      +24     
==========================================
+ Hits         1627     1649      +22     
- Misses        249      251       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexpovel
Copy link
Owner Author

Looks like:

image

tests/cli.rs Outdated Show resolved Hide resolved
tests/cli.rs Outdated Show resolved Hide resolved
This change adds a new flag `--dry-run` that when
given, prevents otherwise destructive file
overwrite operations and instead prints a rich
diff. The diff contains names of files which would
be modified, and a git-like diff of what
modifications *would* be made.

The diff is human-readable, and not designed to be
easily machine-readable.

The change leverages the `similar` crate, on which
we transitively depended on already anyway.

Closes #152.
@alexpovel
Copy link
Owner Author

There's already a search mode, and as opposed to normal diffing tools, we know the exact actions we took. Thus it makes sense to leverage that search mode, and not do (much) extra work to see what changed. Results now look like:

image

which looks different from "normal" git-style diffs, as lines are never grouped. There's also no + and - prefix. I'd think this diff is for human consumption, where the colors and word-style diff make sense.

@alexpovel alexpovel merged commit c2a6d2a into main Nov 3, 2024
17 checks passed
@alexpovel alexpovel deleted the dryrun branch November 3, 2024 20:08
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.

add --dry-run flag
2 participants