forked from mirrors/jj
cargo: upgrade to clap 4.0.4
I changed the "GLOGAL OPTIONS" help heading to use title case, to match clap's new help style. I also removed our override of the help text for `-h, --help` because the default text now includes "(use `-h` for a summary)" (and it's harder override now). Perhaps the most obvious difference to users will be the changed help output (https://epage.github.io/blog/2022/09/clap4/#polishing-help-output). It no longer has color, and long lines are not wrapped. I suppose we should wrap the text ourselves instead..
This commit is contained in:
parent
1665e1dd21
commit
b561a05d25
5 changed files with 67 additions and 58 deletions
55
Cargo.lock
generated
55
Cargo.lock
generated
|
@ -227,31 +227,41 @@ version = "3.2.22"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
"clap_lex",
|
||||
"clap_lex 0.2.4",
|
||||
"indexmap",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "3.2.5"
|
||||
name = "clap"
|
||||
version = "4.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8"
|
||||
checksum = "7f78ad8e84aa8e8aa3e821857be40eb4b925ff232de430d4dd2ae6aa058cbd92"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
"clap_lex 0.3.0",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11cba7abac9b56dfe2f035098cdb3a43946f276e6db83b72c4e692343f9aab9a"
|
||||
dependencies = [
|
||||
"clap 4.0.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.2.18"
|
||||
version = "4.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
|
||||
checksum = "ca689d7434ce44517a12a89456b2be4d1ea1cafcd8f581978c03d45f5a5c12a7"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
|
@ -270,12 +280,21 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_mangen"
|
||||
version = "0.1.11"
|
||||
name = "clap_lex"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "105180c05a72388d5f5e4e4f6c79eecb92497bda749fa8f963a16647c5d5377f"
|
||||
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_mangen"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0941c55fc1417dea79ce9b0745c461002a14b3b905ce2993009b7bada5f99411"
|
||||
dependencies = [
|
||||
"clap 4.0.4",
|
||||
"roff",
|
||||
]
|
||||
|
||||
|
@ -336,7 +355,7 @@ dependencies = [
|
|||
"atty",
|
||||
"cast",
|
||||
"ciborium",
|
||||
"clap",
|
||||
"clap 3.2.22",
|
||||
"criterion-plot",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
|
@ -695,7 +714,7 @@ dependencies = [
|
|||
"assert_cmd",
|
||||
"atty",
|
||||
"chrono",
|
||||
"clap",
|
||||
"clap 4.0.4",
|
||||
"clap_complete",
|
||||
"clap_mangen",
|
||||
"config",
|
||||
|
|
|
@ -36,9 +36,9 @@ members = ["lib"]
|
|||
[dependencies]
|
||||
atty = "0.2.14"
|
||||
chrono = { version = "0.4.22", default-features = false, features = ["std", "clock"] }
|
||||
clap = { version = "3.2.22", features = ["derive"] }
|
||||
clap_complete = "3.2.5"
|
||||
clap_mangen = "0.1"
|
||||
clap = { version = "4.0.4", features = ["derive"] }
|
||||
clap_complete = "4.0.2"
|
||||
clap_mangen = "0.2.1"
|
||||
config = { version = "0.13.2", features = ["toml"] }
|
||||
criterion = "0.4.0"
|
||||
dirs = "4.0.0"
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::env::ArgsOs;
|
||||
use std::ffi::OsString;
|
||||
use std::fmt::Debug;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
@ -168,19 +169,15 @@ impl From<FilePathParseError> for CommandError {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct CommandHelper<'help> {
|
||||
app: clap::Command<'help>,
|
||||
pub struct CommandHelper {
|
||||
app: clap::Command,
|
||||
string_args: Vec<String>,
|
||||
global_args: GlobalArgs,
|
||||
backend_factories: BackendFactories,
|
||||
}
|
||||
|
||||
impl<'help> CommandHelper<'help> {
|
||||
pub fn new(
|
||||
app: clap::Command<'help>,
|
||||
string_args: Vec<String>,
|
||||
global_args: GlobalArgs,
|
||||
) -> Self {
|
||||
impl CommandHelper {
|
||||
pub fn new(app: clap::Command, string_args: Vec<String>, global_args: GlobalArgs) -> Self {
|
||||
Self {
|
||||
app,
|
||||
string_args,
|
||||
|
@ -189,7 +186,7 @@ impl<'help> CommandHelper<'help> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn app(&self) -> &clap::Command<'help> {
|
||||
pub fn app(&self) -> &clap::Command {
|
||||
&self.app
|
||||
}
|
||||
|
||||
|
@ -1066,11 +1063,6 @@ pub fn short_operation_hash(operation_id: &OperationId) -> String {
|
|||
author = "Martin von Zweigbergk <martinvonz@google.com>",
|
||||
version
|
||||
)]
|
||||
#[clap(mut_arg("help", |arg| {
|
||||
arg
|
||||
.help("Print help information, more help with --help than with -h")
|
||||
.help_heading("GLOBAL OPTIONS")
|
||||
}))]
|
||||
pub struct Args {
|
||||
#[clap(flatten)]
|
||||
pub global_args: GlobalArgs,
|
||||
|
@ -1086,7 +1078,7 @@ pub struct GlobalArgs {
|
|||
long,
|
||||
short = 'R',
|
||||
global = true,
|
||||
help_heading = "GLOBAL OPTIONS",
|
||||
help_heading = "Global Options",
|
||||
value_hint = clap::ValueHint::DirPath,
|
||||
)]
|
||||
pub repository: Option<String>,
|
||||
|
@ -1098,7 +1090,7 @@ pub struct GlobalArgs {
|
|||
/// stale working copy commit, you can use `--no-commit-working-copy`.
|
||||
/// This may be useful e.g. in a command prompt, especially if you have
|
||||
/// another process that commits the working copy.
|
||||
#[clap(long, global = true, help_heading = "GLOBAL OPTIONS")]
|
||||
#[clap(long, global = true, help_heading = "Global Options")]
|
||||
pub no_commit_working_copy: bool,
|
||||
/// Operation to load the repo at
|
||||
///
|
||||
|
@ -1122,7 +1114,7 @@ pub struct GlobalArgs {
|
|||
long,
|
||||
visible_alias = "at-op",
|
||||
global = true,
|
||||
help_heading = "GLOBAL OPTIONS",
|
||||
help_heading = "Global Options",
|
||||
default_value = "@"
|
||||
)]
|
||||
pub at_operation: String,
|
||||
|
@ -1131,7 +1123,7 @@ pub struct GlobalArgs {
|
|||
long,
|
||||
value_name = "WHEN",
|
||||
global = true,
|
||||
help_heading = "GLOBAL OPTIONS"
|
||||
help_heading = "Global Options"
|
||||
)]
|
||||
pub color: Option<ColorChoice>,
|
||||
}
|
||||
|
@ -1195,9 +1187,9 @@ fn resolve_aliases(
|
|||
if !real_commands.contains(command_name) {
|
||||
let alias_name = command_name.to_string();
|
||||
let alias_args = submatches
|
||||
.values_of("")
|
||||
.get_many::<OsString>("")
|
||||
.unwrap_or_default()
|
||||
.map(|arg| arg.to_string())
|
||||
.map(|arg| arg.to_str().unwrap().to_string())
|
||||
.collect_vec();
|
||||
if resolved_aliases.contains(&alias_name) {
|
||||
return Err(CommandError::UserError(format!(
|
||||
|
@ -1236,11 +1228,11 @@ fn resolve_aliases(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_args<'help>(
|
||||
pub fn parse_args(
|
||||
ui: &mut Ui,
|
||||
app: clap::Command<'help>,
|
||||
app: clap::Command,
|
||||
args_os: ArgsOs,
|
||||
) -> Result<(CommandHelper<'help>, ArgMatches), CommandError> {
|
||||
) -> Result<(CommandHelper, ArgMatches), CommandError> {
|
||||
let mut string_args: Vec<String> = vec![];
|
||||
for arg_os in args_os {
|
||||
if let Some(string_arg) = arg_os.to_str() {
|
||||
|
|
|
@ -131,7 +131,7 @@ struct VersionArgs {}
|
|||
/// If the given directory does not exist, it will be created. If no directory
|
||||
/// is given, the current directory is used.
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
#[clap(group(ArgGroup::new("backend").args(&["git", "git-repo"])))]
|
||||
#[clap(group(ArgGroup::new("backend").args(&["git", "git_repo"])))]
|
||||
struct InitArgs {
|
||||
/// The destination directory
|
||||
#[clap(default_value = ".", value_hint = clap::ValueHint::DirPath)]
|
||||
|
@ -192,7 +192,7 @@ struct PrintArgs {
|
|||
}
|
||||
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
#[clap(group(ArgGroup::new("format").args(&["summary", "git", "color-words"])))]
|
||||
#[clap(group(ArgGroup::new("format").args(&["summary", "git", "color_words"])))]
|
||||
struct DiffFormatArgs {
|
||||
/// For each path, show only whether it was modified, added, or removed
|
||||
#[clap(long, short)]
|
||||
|
@ -4527,7 +4527,7 @@ fn cmd_git(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn default_app() -> clap::Command<'static> {
|
||||
pub fn default_app() -> clap::Command {
|
||||
let app: clap::Command = Commands::augment_subcommands(Args::command());
|
||||
app.arg_required_else_help(true)
|
||||
}
|
||||
|
|
|
@ -151,20 +151,18 @@ fn test_help() {
|
|||
|
||||
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["touchup", "-h"]);
|
||||
insta::assert_snapshot!(stdout.replace(".exe", ""), @r###"
|
||||
jj-touchup
|
||||
Touch up the content changes in a revision
|
||||
|
||||
USAGE:
|
||||
jj touchup [OPTIONS]
|
||||
Usage: jj touchup [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-r, --revision <REVISION> The revision to touch up [default: @]
|
||||
Options:
|
||||
-r, --revision <REVISION> The revision to touch up [default: @]
|
||||
-h, --help Print help information (use `--help` for more detail)
|
||||
|
||||
GLOBAL OPTIONS:
|
||||
--at-operation <AT_OPERATION> Operation to load the repo at [default: @] [aliases: at-op]
|
||||
--color <WHEN> When to colorize output (always, never, auto)
|
||||
-h, --help Print help information, more help with --help than with -h
|
||||
--no-commit-working-copy Don't commit the working copy
|
||||
-R, --repository <REPOSITORY> Path to repository to operate on
|
||||
Global Options:
|
||||
-R, --repository <REPOSITORY> Path to repository to operate on
|
||||
--no-commit-working-copy Don't commit the working copy
|
||||
--at-operation <AT_OPERATION> Operation to load the repo at [default: @] [aliases: at-op]
|
||||
--color <WHEN> When to colorize output (always, never, auto)
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue