Skip to content

Commit ad4b0ee

Browse files
committed
feat: add clap derive for options struct
1 parent 46aedb2 commit ad4b0ee

File tree

4 files changed

+143
-1
lines changed

4 files changed

+143
-1
lines changed

Cargo.lock

Lines changed: 125 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ description = "Checks if the version control is clean. Based on code from Cargo.
1616
[dependencies]
1717
anyhow = { version = "1.0.94", features = ["backtrace"] }
1818
cargo-util = "0.2.16"
19+
clap = { version = "4.5.23", features = ["cargo", "env", "derive", "wrap_help"], optional = true }
1920
git2 = "0.19.0"
2021
thiserror = "2.0.8"
2122

2223
[dev-dependencies]
2324
rstest = "0.23.0"
2425
strum = { version = "0.26.3", features = ["derive", "strum_macros"] }
26+
27+
[features]
28+
default = []
29+
clap = ["dep:clap"]

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# version-control-clean-check
2+
23
Checks the status of the version control system.
3-
Based on [cargo](https://github.com/rust-lang/cargo)'s [`check_version_control`](https://github.com/rust-lang/cargo/blob/4b84887848a31c6f83434cee2135f4fb0e2c9cf3/src/cargo/ops/fix.rs#L146).
4+
Based on [cargo](https://github.com/rust-lang/cargo)'s [`check_version_control`](https://github.com/rust-lang/cargo/blob/4b84887848a31c6f83434cee2135f4fb0e2c9cf3/src/cargo/ops/fix.rs#L146).
45
In cargo it is used as a safety check before possibly destructive changes are done like running `cargo fix`.
56

7+
# Feature Flags
8+
9+
- clap - Provides clap derives for the options struct
10+
611
## Display Messages for Errors
12+
713
Display messages for errors are meant to be human readable and as such are not considered a breaking change if they are changed for clarity.
814

915
## Tests

src/check.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ use crate::{VCSError, VCSResult};
22
use std::path::Path;
33

44
/// Stores the options available for calling [`check_version_control`] and controls which checks if any are run
5+
#[cfg_attr(feature = "clap", derive(clap::Args))]
56
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
67
pub struct CheckOptions {
78
/// Does not return an error for dirty files nor generate the list of said files
9+
#[cfg_attr(feature = "clap", arg(long))]
810
pub allow_dirty: bool,
11+
912
/// This option basically disables checking. If true no checks are done. (Not even if the `path` exists)
13+
#[cfg_attr(feature = "clap", arg(long))]
1014
pub allow_no_vcs: bool,
15+
1116
/// Does not return an error for staged files nor generate the list of said files
17+
#[cfg_attr(feature = "clap", arg(long))]
1218
pub allow_staged: bool,
1319
}
1420

0 commit comments

Comments
 (0)