From b45c9c8c32f39da4263194148b129530b5e49241 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Sat, 7 Dec 2024 08:53:09 -0500 Subject: [PATCH 1/4] chore: clear clippy lint --- tests/utils/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index d37ee21..6cfa5cc 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -171,6 +171,7 @@ fn modify_files>(path: P, files: &[&str]) -> anyhow::Result<()> { let mut file = fs::OpenOptions::new() .write(true) .create(true) + .truncate(true) .open(file_name)?; file.write_all(b"Some text\n")?; } From 46aedb25e5926e7dd2d73d5a5c0faa82c2735124 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:11:36 -0500 Subject: [PATCH 2/4] chore: update dependencies --- Cargo.lock | 10 +++++----- Cargo.toml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c27962f..39d1506 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1011,18 +1011,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.4" +version = "2.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" +checksum = "08f5383f3e0071702bf93ab5ee99b52d26936be9dedd9413067cbdcddcb6141a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.4" +version = "2.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" +checksum = "f2f357fcec90b3caef6623a099691be676d033b40a058ac95d2a6ade6fa0c943" dependencies = [ "proc-macro2", "quote", @@ -1118,7 +1118,7 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version-control-clean-check" -version = "0.1.3" +version = "0.1.3-dev" dependencies = [ "anyhow", "cargo-util", diff --git a/Cargo.toml b/Cargo.toml index e28d30a..9f414b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "version-control-clean-check" -version = "0.1.3" +version = "0.1.3-dev" authors = ["One "] categories = [] documentation = "https://docs.rs/version-control-clean-check" @@ -17,7 +17,7 @@ description = "Checks if the version control is clean. Based on code from Cargo. anyhow = { version = "1.0.94", features = ["backtrace"] } cargo-util = "0.2.16" git2 = "0.19.0" -thiserror = "2.0.4" +thiserror = "2.0.8" [dev-dependencies] rstest = "0.23.0" From ad4b0ee79416455d6d1a08a4df9a97da0e9ac965 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:32:14 -0500 Subject: [PATCH 3/4] feat: add clap derive for options struct --- Cargo.lock | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 5 +++ README.md | 8 +++- src/check.rs | 6 +++ 4 files changed, 143 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 39d1506..e7d48a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,55 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.94" @@ -121,6 +170,53 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "core-foundation" version = "0.10.0" @@ -573,6 +669,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "jobserver" version = "0.1.32" @@ -952,6 +1054,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.26.3" @@ -1009,6 +1117,16 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "terminal_size" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5352447f921fda68cf61b4101566c0bdb5104eff6804d0678e5227580ab6a4e9" +dependencies = [ + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "thiserror" version = "2.0.8" @@ -1110,6 +1228,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1122,6 +1246,7 @@ version = "0.1.3-dev" dependencies = [ "anyhow", "cargo-util", + "clap", "git2", "rstest", "strum", diff --git a/Cargo.toml b/Cargo.toml index 9f414b6..d3664e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,14 @@ description = "Checks if the version control is clean. Based on code from Cargo. [dependencies] anyhow = { version = "1.0.94", features = ["backtrace"] } cargo-util = "0.2.16" +clap = { version = "4.5.23", features = ["cargo", "env", "derive", "wrap_help"], optional = true } git2 = "0.19.0" thiserror = "2.0.8" [dev-dependencies] rstest = "0.23.0" strum = { version = "0.26.3", features = ["derive", "strum_macros"] } + +[features] +default = [] +clap = ["dep:clap"] diff --git a/README.md b/README.md index 52064f9..7791deb 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,15 @@ # version-control-clean-check + Checks the status of the version control system. -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). +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). In cargo it is used as a safety check before possibly destructive changes are done like running `cargo fix`. +# Feature Flags + +- clap - Provides clap derives for the options struct + ## Display Messages for Errors + 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. ## Tests diff --git a/src/check.rs b/src/check.rs index edcc273..fe8720a 100644 --- a/src/check.rs +++ b/src/check.rs @@ -2,13 +2,19 @@ use crate::{VCSError, VCSResult}; use std::path::Path; /// Stores the options available for calling [`check_version_control`] and controls which checks if any are run +#[cfg_attr(feature = "clap", derive(clap::Args))] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)] pub struct CheckOptions { /// Does not return an error for dirty files nor generate the list of said files + #[cfg_attr(feature = "clap", arg(long))] pub allow_dirty: bool, + /// This option basically disables checking. If true no checks are done. (Not even if the `path` exists) + #[cfg_attr(feature = "clap", arg(long))] pub allow_no_vcs: bool, + /// Does not return an error for staged files nor generate the list of said files + #[cfg_attr(feature = "clap", arg(long))] pub allow_staged: bool, } From b7e99ecb1de67a10dd75cb37460f9ddd82fa34e6 Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:27:12 -0500 Subject: [PATCH 4/4] chore: version bump --- Cargo.lock | 2 +- Cargo.toml | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7d48a0..3e768dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,7 +1242,7 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version-control-clean-check" -version = "0.1.3-dev" +version = "0.1.4" dependencies = [ "anyhow", "cargo-util", diff --git a/Cargo.toml b/Cargo.toml index d3664e9..cd31655 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "version-control-clean-check" -version = "0.1.3-dev" +version = "0.1.4" authors = ["One "] categories = [] documentation = "https://docs.rs/version-control-clean-check" @@ -16,7 +16,12 @@ description = "Checks if the version control is clean. Based on code from Cargo. [dependencies] anyhow = { version = "1.0.94", features = ["backtrace"] } cargo-util = "0.2.16" -clap = { version = "4.5.23", features = ["cargo", "env", "derive", "wrap_help"], optional = true } +clap = { version = "4.5.23", features = [ + "cargo", + "env", + "derive", + "wrap_help", +], optional = true } git2 = "0.19.0" thiserror = "2.0.8"