summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPi-Cla <pirateclip@protonmail.com>2024-03-22 14:52:57 -0600
committerPi-Cla <pirateclip@protonmail.com>2024-03-22 16:14:26 -0600
commited21bed50a659d52c51c4a8d2c3f38bcbb0d4a2a (patch)
tree4a81f55fd0e2b8ae8ba05f2c978ced3bd6ebb004
parent9a123f00374486a35b669e60c9a22add1d1bea27 (diff)
Upgrade to clap 4
I did this because clap 2 and 3 has a dependency on atty which is unmaintained and has a potential security vulnerability https://rustsec.org/advisories/RUSTSEC-2021-0145 clap 4 migration details: - Arg::with_name() has been replaced with Arg::new() - possible_values has been replaced with value_parser - args.value_of has been replaced with args.get_one::<String> - args.gen_completions_to() has been replaced with generate() - The way we use args.is_present() means it is replaced with contains_id() - Shell completion has been moved to the clap_complete crate - app_from_crate! has been replaced with command! * Which now requires a the `cargo` feature flag to access - line wrapping is now behind a feature flag `wrap_help` * Migration guide recommends we enable this or else we would need to manually implement line wrapping - Args are now assumed to take values by default so in order to specify a flag we need to append .action(ArgAction::SetTrue) to each arg. * takes_value() has been removed
-rw-r--r--Cargo.lock231
-rw-r--r--Cargo.toml5
-rw-r--r--src/main.rs88
3 files changed, 219 insertions, 105 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6905a4b..9fe48db 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,32 +3,60 @@
version = 3
[[package]]
-name = "ansi_term"
-version = "0.12.1"
+name = "anstream"
+version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
+checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
dependencies = [
- "winapi",
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "utf8parse",
]
[[package]]
-name = "anyhow"
-version = "1.0.81"
+name = "anstyle"
+version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
+checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
[[package]]
-name = "atty"
-version = "0.2.14"
+name = "anstyle-parse"
+version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
- "hermit-abi 0.1.19",
- "libc",
- "winapi",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
+dependencies = [
+ "windows-sys 0.52.0",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
+dependencies = [
+ "anstyle",
+ "windows-sys 0.52.0",
]
[[package]]
+name = "anyhow"
+version = "1.0.81"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
+
+[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -58,20 +86,48 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
-version = "2.34.0"
+version = "4.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
+checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813"
dependencies = [
- "ansi_term",
- "atty",
- "bitflags 1.3.2",
+ "clap_builder",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap_lex",
"strsim",
- "textwrap",
- "unicode-width",
- "vec_map",
+ "terminal_size",
]
[[package]]
+name = "clap_complete"
+version = "4.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "885e4d7d5af40bfb99ae6f9433e292feac98d452dcb3ec3d25dfe7552b77da8c"
+dependencies = [
+ "clap",
+]
+
+[[package]]
+name = "clap_lex"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
+
+[[package]]
+name = "colorchoice"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
+
+[[package]]
name = "crossbeam-channel"
version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -123,7 +179,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
dependencies = [
"libc",
- "windows-sys",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -158,6 +214,7 @@ version = "0.6.12"
dependencies = [
"anyhow",
"clap",
+ "clap_complete",
"git2",
"memchr",
"slog",
@@ -181,15 +238,6 @@ dependencies = [
[[package]]
name = "hermit-abi"
-version = "0.1.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
-dependencies = [
- "libc",
-]
-
-[[package]]
-name = "hermit-abi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
@@ -210,9 +258,9 @@ version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
dependencies = [
- "hermit-abi 0.3.9",
+ "hermit-abi",
"libc",
- "windows-sys",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -367,7 +415,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
- "windows-sys",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -429,9 +477,9 @@ dependencies = [
[[package]]
name = "strsim"
-version = "0.8.0"
+version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
[[package]]
name = "syn"
@@ -459,7 +507,7 @@ dependencies = [
"cfg-if",
"fastrand",
"rustix",
- "windows-sys",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -474,12 +522,13 @@ dependencies = [
]
[[package]]
-name = "textwrap"
-version = "0.11.0"
+name = "terminal_size"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7"
dependencies = [
- "unicode-width",
+ "rustix",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -580,12 +629,6 @@ dependencies = [
]
[[package]]
-name = "unicode-width"
-version = "0.1.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
-
-[[package]]
name = "url"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -597,16 +640,16 @@ dependencies = [
]
[[package]]
-name = "vcpkg"
-version = "0.2.15"
+name = "utf8parse"
+version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
+checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
-name = "vec_map"
-version = "0.8.2"
+name = "vcpkg"
+version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "wasi"
@@ -638,11 +681,35 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
+dependencies = [
+ "windows-targets 0.48.5",
+]
+
+[[package]]
+name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
- "windows-targets",
+ "windows-targets 0.52.4",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
+dependencies = [
+ "windows_aarch64_gnullvm 0.48.5",
+ "windows_aarch64_msvc 0.48.5",
+ "windows_i686_gnu 0.48.5",
+ "windows_i686_msvc 0.48.5",
+ "windows_x86_64_gnu 0.48.5",
+ "windows_x86_64_gnullvm 0.48.5",
+ "windows_x86_64_msvc 0.48.5",
]
[[package]]
@@ -651,53 +718,95 @@ version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
dependencies = [
- "windows_aarch64_gnullvm",
- "windows_aarch64_msvc",
- "windows_i686_gnu",
- "windows_i686_msvc",
- "windows_x86_64_gnu",
- "windows_x86_64_gnullvm",
- "windows_x86_64_msvc",
+ "windows_aarch64_gnullvm 0.52.4",
+ "windows_aarch64_msvc 0.52.4",
+ "windows_i686_gnu 0.52.4",
+ "windows_i686_msvc 0.52.4",
+ "windows_x86_64_gnu 0.52.4",
+ "windows_x86_64_gnullvm 0.52.4",
+ "windows_x86_64_msvc 0.52.4",
]
[[package]]
name = "windows_aarch64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
+
+[[package]]
+name = "windows_aarch64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
[[package]]
name = "windows_aarch64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
+
+[[package]]
+name = "windows_aarch64_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
[[package]]
name = "windows_i686_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
+
+[[package]]
+name = "windows_i686_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
[[package]]
name = "windows_i686_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
+
+[[package]]
+name = "windows_i686_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
[[package]]
name = "windows_x86_64_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
+
+[[package]]
+name = "windows_x86_64_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
[[package]]
name = "windows_x86_64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
[[package]]
name = "windows_x86_64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
+
+[[package]]
+name = "windows_x86_64_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
diff --git a/Cargo.toml b/Cargo.toml
index 5e45604..2496df7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,7 @@ include = [
"Cargo.*",
"*.md",
]
-rust-version = "1.64.0"
+rust-version = "1.74.1"
[[bin]]
name = "git-absorb"
@@ -26,7 +26,8 @@ version = "0.18"
default-features = false
[dependencies]
-clap = "2.33"
+clap = { version = "4", features = ["cargo", "wrap_help"] }
+clap_complete = "4"
slog = "2.5"
slog-term = "2.6"
slog-async = "2.5"
diff --git a/src/main.rs b/src/main.rs
index 26d0edc..cd75d75 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,89 +4,93 @@ extern crate clap;
#[macro_use]
extern crate slog;
-use clap::Shell;
+use clap::ArgAction;
+use clap_complete::{generate, Shell};
use slog::Drain;
use std::io;
fn main() {
- let args = app_from_crate!()
+ let args = command!()
.about("Automatically absorb staged changes into your current branch")
.arg(
- clap::Arg::with_name("base")
+ clap::Arg::new("base")
.help("Use this commit as the base of the absorb stack")
- .short("b")
- .long("base")
- .takes_value(true),
+ .short('b')
+ .long("base"),
)
.arg(
- clap::Arg::with_name("dry-run")
+ clap::Arg::new("dry-run")
.help("Don't make any actual changes")
- .short("n")
+ .short('n')
.long("dry-run")
- .takes_value(false),
+ .action(ArgAction::SetTrue),
)
.arg(
- clap::Arg::with_name("force")
+ clap::Arg::new("force")
.help("Skip safety checks")
- .short("f")
+ .short('f')
.long("force")
- .takes_value(false),
+ .action(ArgAction::SetTrue),
)
.arg(
- clap::Arg::with_name("verbose")
+ clap::Arg::new("verbose")
.help("Display more output")
- .short("v")
+ .short('v')
.long("verbose")
- .takes_value(false),
+ .action(ArgAction::SetTrue),
)
.arg(
- clap::Arg::with_name("and-rebase")
+ clap::Arg::new("and-rebase")
.help("Run rebase if successful")
- .short("r")
+ .short('r')
.long("and-rebase")
- .takes_value(false),
+ .action(ArgAction::SetTrue),
)
.arg(
- clap::Arg::with_name("gen-completions")
+ clap::Arg::new("gen-completions")
.help("Generate completions")
.long("gen-completions")
- .takes_value(true)
- .possible_values(&["bash", "fish", "zsh", "powershell", "elvish"]),
+ .value_parser(["bash", "fish", "zsh", "powershell", "elvish"]),
)
.arg(
- clap::Arg::with_name("whole-file")
+ clap::Arg::new("whole-file")
.help("Match the change against the complete file ")
- .short("w")
+ .short('w')
.long("whole-file")
- .takes_value(false),
+ .action(ArgAction::SetTrue),
)
.arg(
- clap::Arg::with_name("one-fixup-per-commit")
+ clap::Arg::new("one-fixup-per-commit")
.help("Only generate one fixup per commit")
- .short("F")
+ .short('F')
.long("one-fixup-per-commit")
- .takes_value(false),
+ .action(ArgAction::SetTrue),
);
let mut args_clone = args.clone();
let args = args.get_matches();
- if let Some(shell) = args.value_of("gen-completions") {
+ if let Some(shell) = args.get_one::<String>("gen-completions") {
let app_name = "git-absorb";
- match shell {
+ match shell.as_str() {
"bash" => {
- args_clone.gen_completions_to(app_name, Shell::Bash, &mut io::stdout());
+ generate(Shell::Bash, &mut args_clone, app_name, &mut io::stdout());
}
"fish" => {
- args_clone.gen_completions_to(app_name, Shell::Fish, &mut io::stdout());
+ generate(Shell::Fish, &mut args_clone, app_name, &mut io::stdout());
}
"zsh" => {
- args_clone.gen_completions_to(app_name, Shell::Zsh, &mut io::stdout());
+ generate(Shell::Zsh, &mut args_clone, app_name, &mut io::stdout());
}
"powershell" => {
- args_clone.gen_completions_to(app_name, Shell::PowerShell, &mut io::stdout());
+ generate(
+ Shell::PowerShell,
+ &mut args_clone,
+ app_name,
+ &mut io::stdout(),
+ );
}
"elvish" => {
- args_clone.gen_completions_to(app_name, Shell::Elvish, &mut io::stdout());
+ generate(Shell::Elvish, &mut args_clone, app_name, &mut io::stdout());
}
_ => unreachable!(),
}
@@ -98,7 +102,7 @@ fn main() {
let drain = slog_async::Async::new(drain).build().fuse();
let drain = slog::LevelFilter::new(
drain,
- if args.is_present("verbose") {
+ if args.contains_id("verbose") {
slog::Level::Debug
} else {
slog::Level::Info
@@ -106,7 +110,7 @@ fn main() {
)
.fuse();
let mut logger = slog::Logger::root(drain, o!());
- if args.is_present("verbose") {
+ if args.contains_id("verbose") {
logger = logger.new(o!(
"module" => slog::FnValue(|record| record.module()),
"line" => slog::FnValue(|record| record.line()),
@@ -114,12 +118,12 @@ fn main() {
}
if let Err(e) = git_absorb::run(&mut git_absorb::Config {
- dry_run: args.is_present("dry-run"),
- force: args.is_present("force"),
- base: args.value_of("base"),
- and_rebase: args.is_present("and-rebase"),
- whole_file: args.is_present("whole-file"),
- one_fixup_per_commit: args.is_present("one-fixup-per-commit"),
+ dry_run: args.contains_id("dry-run"),
+ force: args.contains_id("force"),
+ base: args.get_one::<String>("base").map(|s| s.as_str()),
+ and_rebase: args.contains_id("and-rebase"),
+ whole_file: args.contains_id("whole-file"),
+ one_fixup_per_commit: args.contains_id("one-fixup-per-commit"),
logger: &logger,
}) {
crit!(logger, "absorb failed"; "err" => e.to_string());