Skip to content

Commit

Permalink
chore(deps): move to clap 4
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Mar 25, 2024
1 parent 9e46a52 commit 84997dc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 135 deletions.
141 changes: 29 additions & 112 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ ansi_term = "0.12.0"
atty = "0.2.0"
blake3 = { version = "1.5.0", features = ["rayon", "mmap"] }
camino = "1.0.4"
clap = { version = "3.0.0", features = ["wrap_help"] }
clap_complete = "3.0.0"
clap = { version = "4.0.0", features = ["wrap_help"] }
clap_complete = "4.0.0"
ctrlc = { version = "3.1.1", features = ["termination"] }
derivative = "2.0.0"
dirs = "5.0.1"
Expand Down
8 changes: 4 additions & 4 deletions src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub(crate) const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
r" local common=(",
),
(
r"'--set=[Override <VARIABLE> with <VALUE>]:VARIABLE: :VARIABLE: ' \",
r"'--set=[Override <VARIABLE> with <VALUE>]: :(_just_variables)' \",
r"'*--set=[Override <VARIABLE> with <VALUE>]:VARIABLE: :VARIABLE: ' \",
r"'*--set=[Override <VARIABLE> with <VALUE>]: :(_just_variables)' \",
),
(
r"'()-s+[Show information about <RECIPE>]:RECIPE: ' \
Expand Down Expand Up @@ -204,8 +204,8 @@ pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
),
(r" just)", r#" "$1")"#),
(
r"local i cur prev opts cmds",
r"local i cur prev words cword opts cmds",
r"local i cur prev opts cmd",
r"local i cur prev words cword opts cmd",
),
(
r#" cur="${COMP_WORDS[COMP_CWORD]}"
Expand Down
29 changes: 16 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use {
super::*,
clap::{
builder::PossibleValuesParser, value_parser, AppSettings, Arg, ArgAction, ArgGroup, ArgMatches,
Command,
builder::{styling::AnsiColor, PossibleValuesParser, Styles},
value_parser, Arg, ArgAction, ArgGroup, ArgMatches, Command,
},
};

Expand Down Expand Up @@ -139,14 +139,17 @@ mod arg {
}

impl Config {
pub(crate) fn app() -> Command<'static> {
pub(crate) fn app() -> Command {
let app = Command::new(env!("CARGO_PKG_NAME"))
.bin_name(env!("CARGO_PKG_NAME"))
.help_message("Print help information")
.version_message("Print version information")
.setting(AppSettings::ColoredHelp)
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.styles(
Styles::styled()
.header(AnsiColor::Yellow.on_default())
.usage(AnsiColor::Yellow.on_default())
.literal(AnsiColor::Green.on_default())
.placeholder(AnsiColor::Green.on_default())
)
.arg(
Arg::new(arg::CHECK)
.long("check")
Expand Down Expand Up @@ -255,7 +258,7 @@ impl Config {
.long("set")
.action(ArgAction::Append)
.number_of_values(2)
.value_names(&["VARIABLE", "VALUE"])
.value_names(["VARIABLE", "VALUE"])
.help("Override <VARIABLE> with <VALUE>"),
)
.arg(
Expand Down Expand Up @@ -326,7 +329,7 @@ impl Config {
Arg::new(cmd::COMMAND)
.long("command")
.short('c')
.min_values(1)
.num_args(1..)
.allow_hyphen_values(true)
.action(ArgAction::Append)
.value_parser(value_parser!(std::ffi::OsString))
Expand All @@ -339,7 +342,7 @@ impl Config {
Arg::new(cmd::COMPLETIONS)
.long("completions")
.action(ArgAction::Append)
.min_values(1)
.num_args(1..)
.value_name("SHELL")
.value_parser(value_parser!(clap_complete::Shell))
.ignore_case(true)
Expand Down Expand Up @@ -427,7 +430,7 @@ impl Config {
.group(ArgGroup::new("SUBCOMMAND").args(cmd::ALL))
.arg(
Arg::new(arg::ARGUMENTS)
.multiple_values(true)
.num_args(1..)
.action(ArgAction::Append)
.help("Overrides and recipe(s) to run, defaulting to the first recipe in the justfile"),
);
Expand Down Expand Up @@ -1537,8 +1540,8 @@ mod tests {
assert_eq!(error.kind(), clap::error::ErrorKind::ArgumentConflict);
assert_eq!(error.context().collect::<Vec<_>>(), vec![
(ContextKind::InvalidArg, &ContextValue::String("--show <RECIPE>".into())),
(ContextKind::PriorArg, &ContextValue::String("<ARGUMENTS>...".into())),
(ContextKind::Usage, &ContextValue::String("USAGE:\n just <--changelog|--choose|--command <COMMAND>...|--completions <SHELL>...|--dump|--edit|--evaluate|--fmt|--init|--list|--show <RECIPE>|--summary|--variables>".into())),
(ContextKind::PriorArg, &ContextValue::String("[ARGUMENTS]...".into())),
(ContextKind::Usage, &ContextValue::StyledStr("\u{1b}[33mUsage:\u{1b}[0m \u{1b}[32mjust\u{1b}[0m \u{1b}[32m--show\u{1b}[0m\u{1b}[32m \u{1b}[0m\u{1b}[32m<RECIPE>\u{1b}[0m \u{1b}[32m[ARGUMENTS]...\u{1b}[0m".into())),
]);
},
}
Expand Down
4 changes: 2 additions & 2 deletions tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ test! {
",
args: ("--command"),
stderr: "
error: The argument '--command <COMMAND>...' requires a value but none was supplied
error: a value is required for '--command <COMMAND>...' but none was supplied
For more information try --help
For more information, try '--help'.
",
status: 2,
}
Expand Down
Loading

0 comments on commit 84997dc

Please sign in to comment.