diff --git a/src/main.rs b/src/main.rs index 5d7c59c..fbdfcd1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); - } else { - line.arg("test"); - } - } else if args.release { - line.arg("release"); - } else { - line.arg("check"); + if args.verbose { + line.arg("--verbose"); } - if let Some(features) = &args.features { - line.arg("--features"); - line.arg(features); + 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.all_features { - line.arg("--all-features"); + for unstable_flag in &args.unstable_flags { + line.arg("-Z"); + line.arg(unstable_flag); } - 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,24 +326,17 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path } } - if let Some(target) = &args.target { - line.arg("--target"); - line.arg(target); - } - - if let Some(target_dir) = &args.target_dir { - line.arg("--target-dir"); - line.arg(target_dir); + if let Some(features) = &args.features { + line.arg("--features"); + line.arg(features); } - if let Some(manifest_path) = &args.manifest_path { - line.arg("--manifest-path"); - line.arg(manifest_path); + if args.all_features { + line.arg("--all-features"); } - if let Some(package) = &args.package { - line.arg("--package"); - line.args(package); + if args.no_default_features { + line.arg("--no-default-features"); } if let Some(jobs) = args.jobs { @@ -355,18 +344,34 @@ fn apply_args(cmd: &mut Command, args: &Expand, color: &Coloring, outfile: &Path line.arg(jobs.to_string()); } - if args.verbose { - line.arg("--verbose"); + 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"); } - 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 let Some(target) = &args.target { + line.arg("--target"); + line.arg(target); + } + + if let Some(target_dir) = &args.target_dir { + line.arg("--target-dir"); + line.arg(target_dir); + } + + if let Some(manifest_path) = &args.manifest_path { + line.arg("--manifest-path"); + line.arg(manifest_path); } if args.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"); diff --git a/src/opts.rs b/src/opts.rs index 4598454..3566c7c 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -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,113 +20,113 @@ pub enum Subcommand { #[derive(Parser, Debug)] pub struct Expand { - /// Space-separated list of features to activate - #[arg(long, value_name = "FEATURES")] - pub features: Option, + /// Do not attempt to run rustfmt + #[arg(long)] + pub ugly: bool, - /// Activate all available features + /// Select syntax highlighting theme + #[arg(long, value_name = "NAME")] + pub theme: Option, + + /// Print available syntax highlighting theme names #[arg(long)] - pub all_features: bool, + pub themes: bool, - /// Do not activate the `default` feature + /// Print command lines as they are executed #[arg(long)] - pub no_default_features: bool, + pub verbose: bool, - /// Expand only this package's library + /// Coloring: auto, always, never + #[arg(long, value_name = "WHEN")] + pub color: Option, + + /// Unstable (nightly-only) flags to Cargo + #[arg(short = 'Z', value_name = "FLAG")] + pub unstable_flags: Vec, + + /// 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>, + + /// 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)] + #[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)] pub bin: Option>, /// Expand only the specified example - #[arg(long, value_name = "NAME", num_args = 0..=1)] + #[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)] pub example: Option>, /// Expand only the specified test target - #[arg(long, value_name = "NAME", num_args = 0..=1)] + #[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)] pub test: Option>, /// Include tests when expanding the lib or bin - #[arg(long)] + #[arg(long, help_heading = TARGET_SELECTION)] pub tests: bool, /// Expand only the specified bench target - #[arg(long, value_name = "NAME", num_args = 0..=1)] + #[arg(long, value_name = "NAME", num_args = 0..=1, help_heading = TARGET_SELECTION)] pub bench: Option>, - /// Target triple which compiles will be for - #[arg(long, value_name = "TARGET")] - pub target: Option, + /// Space-separated list of features to activate + #[arg(long, value_name = "FEATURES", help_heading = FEATURE_SELECTION)] + pub features: Option, - /// Directory for all generated artifacts - #[arg(long, value_name = "DIRECTORY")] - pub target_dir: Option, + /// Activate all available features + #[arg(long, help_heading = FEATURE_SELECTION)] + pub all_features: bool, - /// Path to Cargo.toml - #[arg(long, value_name = "PATH")] - pub manifest_path: Option, + /// Do not activate the `default` feature + #[arg(long, help_heading = FEATURE_SELECTION)] + pub no_default_features: bool, - /// Package to expand - #[arg(short, long, value_name = "SPEC", num_args = 0..=1)] - pub package: Option>, + /// Number of parallel jobs, defaults to # of CPUs + #[arg(short, long, value_name = "N", help_heading = COMPILATION_OPTIONS)] + pub jobs: Option, /// Build artifacts in release mode, with optimizations - #[arg(long)] + #[arg(long, help_heading = COMPILATION_OPTIONS)] pub release: bool, /// Build artifacts with the specified profile - #[arg(long, value_name = "PROFILE-NAME")] + #[arg(long, value_name = "PROFILE-NAME", help_heading = COMPILATION_OPTIONS)] pub profile: Option, - /// Number of parallel jobs, defaults to # of CPUs - #[arg(short, long, value_name = "N")] - pub jobs: Option, + /// Target triple which compiles will be for + #[arg(long, value_name = "TARGET", help_heading = COMPILATION_OPTIONS)] + pub target: Option, - /// Print command lines as they are executed - #[arg(long)] - pub verbose: bool, + /// Directory for all generated artifacts + #[arg(long, value_name = "DIRECTORY", help_heading = COMPILATION_OPTIONS)] + pub target_dir: Option, - /// Coloring: auto, always, never - #[arg(long, value_name = "WHEN")] - pub color: Option, + /// Path to Cargo.toml + #[arg(long, value_name = "PATH", help_heading = MANIFEST_OPTIONS)] + pub manifest_path: Option, /// Require Cargo.lock and cache are up to date - #[arg(long)] + #[arg(long, help_heading = MANIFEST_OPTIONS)] pub frozen: bool, /// Require Cargo.lock is up to date - #[arg(long)] + #[arg(long, help_heading = MANIFEST_OPTIONS)] pub locked: bool, /// Run without accessing the network - #[arg(long)] + #[arg(long, help_heading = MANIFEST_OPTIONS)] pub offline: bool, - /// Unstable (nightly-only) flags to Cargo - #[arg(short = 'Z', value_name = "FLAG")] - pub unstable_flags: Vec, - - /// Do not attempt to run rustfmt - #[arg(long)] - pub ugly: bool, - - /// Select syntax highlighting theme - #[arg(long, value_name = "NAME")] - pub theme: Option, - - /// Print available syntax highlighting theme names - #[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, - - /// Print version - #[arg(long)] - pub version: bool, } #[derive(ValueEnum, Debug, Clone, Copy)]