let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() {
"build" | "bench" | "check" | "clean" | "doc" | "fetch" | "generate-lockfile" | "git-checkout" |
"init" | "install" | "locate-project" | "login" | "metadata" | "new" |
- "owner" | "package" | "pkgid" | "publish" | "read-manifest" => true,
+ "owner" | "package" | "pkgid" | "publish" | "read-manifest" | "run" => true,
_ => false
});
// $mac!(pkgid);
// $mac!(publish);
// $mac!(read_manifest);
- $mac!(run);
+// $mac!(run);
$mac!(rustc);
$mac!(rustdoc);
$mac!(search);
cargo::print_json(&pkg);
return Ok(());
}
+ ("run", Some(args)) => {
+ let ws = workspace_from_args(config, args)?;
+
+ let mut compile_opts = compile_options_from_args(config, args, CompileMode::Build)?;
+ let packages = values(args, "package");
+ compile_opts.spec = Packages::Packages(&packages);
+ if !args.is_present("example") && !args.is_present("bin") {
+ compile_opts.filter = ops::CompileFilter::Default {
+ required_features_filterable: false,
+ };
+ };
+ match ops::run(&ws, &compile_opts, &values(args, "args"))? {
+ None => Ok(()),
+ Some(err) => {
+ // If we never actually spawned the process then that sounds pretty
+ // bad and we always want to forward that up.
+ let exit = match err.exit {
+ Some(exit) => exit,
+ None => return Err(CliError::new(err.into(), 101)),
+ };
+
+ // If `-q` was passed then we suppress extra error information about
+ // a failed process, we assume the process itself printed out enough
+ // information about why it failed so we don't do so as well
+ let exit_code = exit.code().unwrap_or(101);
+ Err(if args.is_present("quite") {
+ CliError::code(exit_code)
+ } else {
+ CliError::new(err.into(), exit_code)
+ })
+ }
+ }
+ }
_ => return Ok(())
}
}
pkgid::cli(),
publish::cli(),
read_manifest::cli(),
+ run::cli(),
])
;
app
mod pkgid;
mod publish;
mod read_manifest;
+mod run;
mod utils {
use clap::{self, SubCommand, AppSettings};
._arg(opt("bins", bins))
}
- fn arg_targets_bin_example(
+ fn arg_targets_bins_examples(
self,
bin: &'static str,
bins: &'static str,
._arg(opt("examples", examples))
}
+ fn arg_targets_bin_example(
+ self,
+ bin: &'static str,
+ example: &'static str,
+ ) -> Self {
+ self._arg(opt("bin", bin).value_name("NAME").multiple(true))
+ ._arg(opt("example", example).value_name("NAME").multiple(true))
+ }
+
fn arg_features(self) -> Self {
self
._arg(
--- /dev/null
+extern crate clap;
+
+use super::utils::*;
+use clap::AppSettings;
+
+pub fn cli() -> App {
+ subcommand("run")
+ .setting(AppSettings::TrailingVarArg)
+ .about("Run the main binary of the local package (src/main.rs)")
+ .arg(Arg::with_name("args").multiple(true))
+ .arg_targets_bin_example(
+ "Name of the bin target to run",
+ "Name of the example target to run",
+ )
+ .arg(
+ opt("package", "Package with the target to run")
+ .short("p").value_name("SPEC")
+ )
+ .arg_jobs()
+ .arg_release("Build artifacts in release mode, with optimizations")
+ .arg_features()
+ .arg_target_triple("Build for the target triple")
+ .arg_manifest_path()
+ .arg_message_format()
+ .after_help("\
+If neither `--bin` nor `--example` are given, then if the project only has one
+bin target it will be run. Otherwise `--bin` specifies the bin target to run,
+and `--example` specifies the example target to run. At most one of `--bin` or
+`--example` can be provided.
+
+All of the trailing arguments are passed to the binary to run. If you're passing
+arguments to both Cargo and the binary, the ones after `--` go to the binary,
+the ones before go to Cargo.
+")
+}