mirror of
https://github.com/dtolnay/cargo-expand.git
synced 2025-04-03 12:57:38 +03:00
Update argument parser to clap 4
This commit is contained in:
parent
f597166c59
commit
1a6b14a973
3 changed files with 38 additions and 81 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -171,24 +171,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.2.22"
|
||||
version = "4.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
|
||||
checksum = "dd03107d0f87139c1774a15f3db2165b0652b5460c58c27e561f89c20c599eaf"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
"clap_lex",
|
||||
"indexmap",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"textwrap",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[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",
|
||||
|
@ -199,9 +199,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.2.4"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
|
||||
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
@ -789,12 +789,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.37"
|
||||
|
|
|
@ -19,7 +19,7 @@ prettyplease = []
|
|||
atty = "0.2"
|
||||
bat = { version = "0.22", default-features = false, features = ["paging", "regex-fancy"] }
|
||||
cargo-subcommand-metadata = "0.1"
|
||||
clap = { version = "3.2.5", default-features = false, features = ["deprecated", "derive", "std", "suggestions"] }
|
||||
clap = { version = "4", features = ["deprecated", "derive"] }
|
||||
prettyplease = { version = "0.1.18", features = ["verbatim"] }
|
||||
proc-macro2 = "1.0"
|
||||
quote = { version = "1.0", default-features = false }
|
||||
|
|
95
src/opts.rs
95
src/opts.rs
|
@ -1,4 +1,4 @@
|
|||
use clap::{AppSettings, Parser};
|
||||
use clap::Parser;
|
||||
use std::fmt::{self, Display};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
@ -7,154 +7,117 @@ use syn_select::Selector;
|
|||
const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version"));
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(bin_name = "cargo", version = VERSION, author)]
|
||||
#[command(bin_name = "cargo", version = VERSION, author)]
|
||||
pub enum Opts {
|
||||
/// Show the result of macro expansion.
|
||||
#[clap(
|
||||
name = "expand",
|
||||
version = VERSION,
|
||||
author,
|
||||
setting = AppSettings::DeriveDisplayOrder,
|
||||
dont_collapse_args_in_usage = true
|
||||
)]
|
||||
#[command(name = "expand", version = VERSION, author)]
|
||||
Expand(Args),
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Args {
|
||||
/// Space-separated list of features to activate
|
||||
#[clap(long, value_name = "FEATURES", action)]
|
||||
#[arg(long, value_name = "FEATURES")]
|
||||
pub features: Option<String>,
|
||||
|
||||
/// Activate all available features
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub all_features: bool,
|
||||
|
||||
/// Do not activate the `default` feature
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub no_default_features: bool,
|
||||
|
||||
/// Expand only this package's library
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub lib: bool,
|
||||
|
||||
/// Expand only the specified binary
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "NAME",
|
||||
min_values = 0,
|
||||
multiple_values = false,
|
||||
action
|
||||
)]
|
||||
#[arg(long, value_name = "NAME", num_args = 0..=1)]
|
||||
pub bin: Option<Option<String>>,
|
||||
|
||||
/// Expand only the specified example
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "NAME",
|
||||
min_values = 0,
|
||||
multiple_values = false,
|
||||
action
|
||||
)]
|
||||
#[arg(long, value_name = "NAME", num_args = 0..=1)]
|
||||
pub example: Option<Option<String>>,
|
||||
|
||||
/// Expand only the specified test target
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "NAME",
|
||||
min_values = 0,
|
||||
multiple_values = false,
|
||||
action
|
||||
)]
|
||||
#[arg(long, value_name = "NAME", num_args = 0..=1)]
|
||||
pub test: Option<Option<String>>,
|
||||
|
||||
/// Include tests when expanding the lib or bin
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub tests: bool,
|
||||
|
||||
/// Expand only the specified bench target
|
||||
#[clap(
|
||||
long,
|
||||
value_name = "NAME",
|
||||
min_values = 0,
|
||||
multiple_values = false,
|
||||
action
|
||||
)]
|
||||
#[arg(long, value_name = "NAME", num_args = 0..=1)]
|
||||
pub bench: Option<Option<String>>,
|
||||
|
||||
/// Target triple which compiles will be for
|
||||
#[clap(long, value_name = "TARGET", action)]
|
||||
#[arg(long, value_name = "TARGET")]
|
||||
pub target: Option<String>,
|
||||
|
||||
/// Directory for all generated artifacts
|
||||
#[clap(long, value_name = "DIRECTORY", action)]
|
||||
#[arg(long, value_name = "DIRECTORY")]
|
||||
pub target_dir: Option<PathBuf>,
|
||||
|
||||
/// Path to Cargo.toml
|
||||
#[clap(long, value_name = "PATH", action)]
|
||||
#[arg(long, value_name = "PATH")]
|
||||
pub manifest_path: Option<PathBuf>,
|
||||
|
||||
/// Package to expand
|
||||
#[clap(
|
||||
short,
|
||||
long,
|
||||
value_name = "SPEC",
|
||||
min_values = 0,
|
||||
multiple_values = false,
|
||||
action
|
||||
)]
|
||||
#[arg(short, long, value_name = "SPEC", num_args = 0..=1)]
|
||||
pub package: Option<Option<String>>,
|
||||
|
||||
/// Build artifacts in release mode, with optimizations
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub release: bool,
|
||||
|
||||
/// Build artifacts with the specified profile
|
||||
#[clap(long, value_name = "PROFILE-NAME", action)]
|
||||
#[arg(long, value_name = "PROFILE-NAME")]
|
||||
pub profile: Option<String>,
|
||||
|
||||
/// Number of parallel jobs, defaults to # of CPUs
|
||||
#[clap(short, long, value_name = "N", action)]
|
||||
#[arg(short, long, value_name = "N")]
|
||||
pub jobs: Option<u64>,
|
||||
|
||||
/// Print command lines as they are executed
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub verbose: bool,
|
||||
|
||||
/// Coloring: auto, always, never
|
||||
#[clap(long, value_name = "WHEN", action)]
|
||||
#[arg(long, value_name = "WHEN")]
|
||||
pub color: Option<Coloring>,
|
||||
|
||||
/// Require Cargo.lock and cache are up to date
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub frozen: bool,
|
||||
|
||||
/// Require Cargo.lock is up to date
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub locked: bool,
|
||||
|
||||
/// Run without accessing the network
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub offline: bool,
|
||||
|
||||
/// Unstable (nightly-only) flags to Cargo
|
||||
#[clap(short = 'Z', value_name = "FLAG", action)]
|
||||
#[arg(short = 'Z', value_name = "FLAG")]
|
||||
pub unstable_flags: Vec<String>,
|
||||
|
||||
/// Do not attempt to run rustfmt
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub ugly: bool,
|
||||
|
||||
/// Select syntax highlighting theme
|
||||
#[clap(long, value_name = "NAME", action)]
|
||||
#[arg(long, value_name = "NAME")]
|
||||
pub theme: Option<String>,
|
||||
|
||||
/// Print available syntax highlighting theme names
|
||||
#[clap(long, action)]
|
||||
#[arg(long)]
|
||||
pub themes: bool,
|
||||
|
||||
/// Local path to module or other named item to expand, e.g. os::unix::ffi
|
||||
#[clap(value_name = "ITEM", value_parser = parse_selector)]
|
||||
#[arg(value_name = "ITEM", value_parser = parse_selector)]
|
||||
pub item: Option<Selector>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue