|
| 1 | +use crate::command_prelude::*; |
| 2 | + |
| 3 | +use cargo::ops; |
| 4 | + |
| 5 | +pub fn cli() -> App { |
| 6 | + subcommand("clippy-preview") |
| 7 | + // subcommand aliases are handled in aliased_command() |
| 8 | + // .alias("c") |
| 9 | + .about("Check a local package and all of its dependencies for errors") |
| 10 | + .arg_package_spec( |
| 11 | + "Package(s) to check", |
| 12 | + "Check all packages in the workspace", |
| 13 | + "Exclude packages from the check", |
| 14 | + ) |
| 15 | + .arg_jobs() |
| 16 | + .arg_targets_all( |
| 17 | + "Check only this package's library", |
| 18 | + "Check only the specified binary", |
| 19 | + "Check all binaries", |
| 20 | + "Check only the specified example", |
| 21 | + "Check all examples", |
| 22 | + "Check only the specified test target", |
| 23 | + "Check all tests", |
| 24 | + "Check only the specified bench target", |
| 25 | + "Check all benches", |
| 26 | + "Check all targets", |
| 27 | + ) |
| 28 | + .arg_release("Check artifacts in release mode, with optimizations") |
| 29 | + .arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE")) |
| 30 | + .arg_features() |
| 31 | + .arg_target_triple("Check for the target triple") |
| 32 | + .arg_target_dir() |
| 33 | + .arg_manifest_path() |
| 34 | + .arg_message_format() |
| 35 | + .after_help( |
| 36 | + "\ |
| 37 | +If the `--package` argument is given, then SPEC is a package ID specification |
| 38 | +which indicates which package should be built. If it is not given, then the |
| 39 | +current package is built. For more information on SPEC and its format, see the |
| 40 | +`cargo help pkgid` command. |
| 41 | +
|
| 42 | +All packages in the workspace are checked if the `--all` flag is supplied. The |
| 43 | +`--all` flag is automatically assumed for a virtual manifest. |
| 44 | +Note that `--exclude` has to be specified in conjunction with the `--all` flag. |
| 45 | +
|
| 46 | +Compilation can be configured via the use of profiles which are configured in |
| 47 | +the manifest. The default profile for this command is `dev`, but passing |
| 48 | +the `--release` flag will use the `release` profile instead. |
| 49 | +
|
| 50 | +The `--profile test` flag can be used to check unit tests with the |
| 51 | +`#[cfg(test)]` attribute. |
| 52 | +", |
| 53 | + ) |
| 54 | +} |
| 55 | + |
| 56 | +pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { |
| 57 | + config.set_clippy_override(true); |
| 58 | + let ws = args.workspace(config)?; |
| 59 | + let test = match args.value_of("profile") { |
| 60 | + Some("test") => true, |
| 61 | + None => false, |
| 62 | + Some(profile) => { |
| 63 | + let err = failure::format_err!( |
| 64 | + "unknown profile: `{}`, only `test` is \ |
| 65 | + currently supported", |
| 66 | + profile |
| 67 | + ); |
| 68 | + return Err(CliError::new(err, 101)); |
| 69 | + } |
| 70 | + }; |
| 71 | + let mode = CompileMode::Check { test }; |
| 72 | + let compile_opts = args.compile_options(config, mode, Some(&ws))?; |
| 73 | + |
| 74 | + ops::compile(&ws, &compile_opts)?; |
| 75 | + Ok(()) |
| 76 | +} |
0 commit comments