Merge pull request #194 from dtolnay/helpheading

Add help headings matching `cargo rustc --help`
This commit is contained in:
David Tolnay 2023-09-23 13:42:37 -07:00 committed by GitHub
commit a4a2dcac97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 148 additions and 141 deletions

View file

@ -261,32 +261,28 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path
line.arg("rustc");
line.arg("--profile");
if let Some(profile) = &args.profile {
line.arg(profile);
} else if args.tests && args.test.is_none() {
if args.release {
line.arg("bench");
if args.verbose {
line.arg("--verbose");
}
line.arg("--color");
match color {
Coloring::Auto => line.arg(if cfg!(not(windows)) && io::stderr().is_terminal() {
"always"
} else {
line.arg("test");
}
} else if args.release {
line.arg("release");
} else {
line.arg("check");
"never"
}),
color => line.arg(color.to_possible_value().unwrap().get_name()),
}
if let Some(features) = &args.features {
line.arg("--features");
line.arg(features);
for unstable_flag in &args.unstable_flags {
line.arg("-Z");
line.arg(unstable_flag);
}
if args.all_features {
line.arg("--all-features");
}
if args.no_default_features {
line.arg("--no-default-features");
if let Some(package) = &args.package {
line.arg("--package");
line.args(package);
}
let mut has_explicit_build_target = false;
@ -330,6 +326,39 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path
}
}
if let Some(features) = &args.features {
line.arg("--features");
line.arg(features);
}
if args.all_features {
line.arg("--all-features");
}
if args.no_default_features {
line.arg("--no-default-features");
}
if let Some(jobs) = args.jobs {
line.arg("--jobs");
line.arg(jobs.to_string());
}
line.arg("--profile");
if let Some(profile) = &args.profile {
line.arg(profile);
} else if args.tests && args.test.is_none() {
if args.release {
line.arg("bench");
} else {
line.arg("test");
}
} else if args.release {
line.arg("release");
} else {
line.arg("check");
}
if let Some(target) = &args.target {
line.arg("--target");
line.arg(target);
@ -345,30 +374,6 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path
line.arg(manifest_path);
}
if let Some(package) = &args.package {
line.arg("--package");
line.args(package);
}
if let Some(jobs) = args.jobs {
line.arg("--jobs");
line.arg(jobs.to_string());
}
if args.verbose {
line.arg("--verbose");
}
line.arg("--color");
match color {
Coloring::Auto => line.arg(if cfg!(not(windows)) && io::stderr().is_terminal() {
"always"
} else {
"never"
}),
color => line.arg(color.to_possible_value().unwrap().get_name()),
}
if args.frozen {
line.arg("--frozen");
}
@ -381,11 +386,6 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path
line.arg("--offline");
}
for unstable_flag in &args.unstable_flags {
line.arg("-Z");
line.arg(unstable_flag);
}
line.arg("--");
line.arg("-o");

View file

@ -3,6 +3,13 @@ use std::path::PathBuf;
use std::str::FromStr;
use syn_select::Selector;
// Help headings
const PACKAGE_SELECTION: &str = "Package Selection";
const TARGET_SELECTION: &str = "Target Selection";
const FEATURE_SELECTION: &str = "Feature Selection";
const COMPILATION_OPTIONS: &str = "Compilation Options";
const MANIFEST_OPTIONS: &str = "Manifest Options";
#[derive(Parser)]
#[command(bin_name = "cargo", version, author, disable_help_subcommand = true)]
pub enum Subcommand {
@ -13,94 +20,6 @@ pub enum Subcommand {
#[derive(Parser, Debug)]
pub struct Expand {
/// Space-separated list of features to activate
#[arg(long, value_name = "FEATURES")]
pub features: Option<String>,
/// Activate all available features
#[arg(long)]
pub all_features: bool,
/// Do not activate the `default` feature
#[arg(long)]
pub no_default_features: bool,
/// Expand only this package's library
#[arg(long)]
pub lib: bool,
/// Expand only the specified binary
#[arg(long, value_name = "NAME", num_args = 0..=1)]
pub bin: Option<Option<String>>,
/// Expand only the specified example
#[arg(long, value_name = "NAME", num_args = 0..=1)]
pub example: Option<Option<String>>,
/// Expand only the specified test target
#[arg(long, value_name = "NAME", num_args = 0..=1)]
pub test: Option<Option<String>>,
/// Include tests when expanding the lib or bin
#[arg(long)]
pub tests: bool,
/// Expand only the specified bench target
#[arg(long, value_name = "NAME", num_args = 0..=1)]
pub bench: Option<Option<String>>,
/// Target triple which compiles will be for
#[arg(long, value_name = "TARGET")]
pub target: Option<String>,
/// Directory for all generated artifacts
#[arg(long, value_name = "DIRECTORY")]
pub target_dir: Option<PathBuf>,
/// Path to Cargo.toml
#[arg(long, value_name = "PATH")]
pub manifest_path: Option<PathBuf>,
/// Package to expand
#[arg(short, long, value_name = "SPEC", num_args = 0..=1)]
pub package: Option<Option<String>>,
/// Build artifacts in release mode, with optimizations
#[arg(long)]
pub release: bool,
/// Build artifacts with the specified profile
#[arg(long, value_name = "PROFILE-NAME")]
pub profile: Option<String>,
/// Number of parallel jobs, defaults to # of CPUs
#[arg(short, long, value_name = "N")]
pub jobs: Option<u64>,
/// Print command lines as they are executed
#[arg(long)]
pub verbose: bool,
/// Coloring: auto, always, never
#[arg(long, value_name = "WHEN")]
pub color: Option<Coloring>,
/// Require Cargo.lock and cache are up to date
#[arg(long)]
pub frozen: bool,
/// Require Cargo.lock is up to date
#[arg(long)]
pub locked: bool,
/// Run without accessing the network
#[arg(long)]
pub offline: bool,
/// Unstable (nightly-only) flags to Cargo
#[arg(short = 'Z', value_name = "FLAG")]
pub unstable_flags: Vec<String>,
/// Do not attempt to run rustfmt
#[arg(long)]
pub ugly: bool,
@ -113,13 +32,101 @@ pub struct Expand {
#[arg(long)]
pub themes: bool,
/// Local path to module or other named item to expand, e.g. os::unix::ffi
#[arg(value_name = "ITEM", value_parser = parse_selector)]
pub item: Option<Selector>,
/// Print command lines as they are executed
#[arg(long)]
pub verbose: bool,
/// Coloring: auto, always, never
#[arg(long, value_name = "WHEN")]
pub color: Option<Coloring>,
/// Unstable (nightly-only) flags to Cargo
#[arg(short = 'Z', value_name = "FLAG")]
pub unstable_flags: Vec<String>,
/// Print version
#[arg(long)]
pub version: bool,
/// Package to expand
#[arg(short, long, value_name = "SPEC", num_args = 0..=1, help_heading = PACKAGE_SELECTION)]
pub package: Option<Option<String>>,
/// Expand only this package's library
#[arg(long, help_heading = TARGET_SELECTION)]
pub lib: bool,
/// Expand only the specified binary
#[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)]
pub bin: Option<Option<String>>,
/// Expand only the specified example
#[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)]
pub example: Option<Option<String>>,
/// Expand only the specified test target
#[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)]
pub test: Option<Option<String>>,
/// Include tests when expanding the lib or bin
#[arg(long, help_heading = TARGET_SELECTION)]
pub tests: bool,
/// Expand only the specified bench target
#[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)]
pub bench: Option<Option<String>>,
/// Space-separated list of features to activate
#[arg(long, value_name = "FEATURES", help_heading = FEATURE_SELECTION)]
pub features: Option<String>,
/// Activate all available features
#[arg(long, help_heading = FEATURE_SELECTION)]
pub all_features: bool,
/// Do not activate the `default` feature
#[arg(long, help_heading = FEATURE_SELECTION)]
pub no_default_features: bool,
/// Number of parallel jobs, defaults to # of CPUs
#[arg(short, long, value_name = "N", help_heading = COMPILATION_OPTIONS)]
pub jobs: Option<u64>,
/// Build artifacts in release mode, with optimizations
#[arg(long, help_heading = COMPILATION_OPTIONS)]
pub release: bool,
/// Build artifacts with the specified profile
#[arg(long, value_name = "PROFILE-NAME", help_heading = COMPILATION_OPTIONS)]
pub profile: Option<String>,
/// Target triple which compiles will be for
#[arg(long, value_name = "TARGET", help_heading = COMPILATION_OPTIONS)]
pub target: Option<String>,
/// Directory for all generated artifacts
#[arg(long, value_name = "DIRECTORY", help_heading = COMPILATION_OPTIONS)]
pub target_dir: Option<PathBuf>,
/// Path to Cargo.toml
#[arg(long, value_name = "PATH", help_heading = MANIFEST_OPTIONS)]
pub manifest_path: Option<PathBuf>,
/// Require Cargo.lock and cache are up to date
#[arg(long, help_heading = MANIFEST_OPTIONS)]
pub frozen: bool,
/// Require Cargo.lock is up to date
#[arg(long, help_heading = MANIFEST_OPTIONS)]
pub locked: bool,
/// Run without accessing the network
#[arg(long, help_heading = MANIFEST_OPTIONS)]
pub offline: bool,
/// Local path to module or other named item to expand, e.g. os::unix::ffi
#[arg(value_name = "ITEM", value_parser = parse_selector)]
pub item: Option<Selector>,
}
#[derive(ValueEnum, Debug, Clone, Copy)]