Drop old commands

This commit is contained in:
Aleksey Kladov 2018-03-08 21:27:51 +03:00
parent 666e232b59
commit c327245ca5
35 changed files with 13 additions and 2757 deletions

View File

@ -1,159 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, CliError, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct Options {
flag_no_run: bool,
flag_package: Vec<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_lib: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_example: Vec<String>,
flag_examples: bool,
flag_test: Vec<String>,
flag_tests: bool,
flag_bench: Vec<String>,
flag_benches: bool,
flag_all_targets: bool,
flag_no_fail_fast: bool,
flag_frozen: bool,
flag_locked: bool,
arg_args: Vec<String>,
flag_all: bool,
flag_exclude: Vec<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
#[serde(rename = "arg_BENCHNAME")]
arg_benchname: Option<String>,
}
pub const USAGE: &'static str = "
Execute all benchmarks of a local package
Usage:
cargo bench [options] [BENCHNAME] [--] [<args>...]
Options:
BENCHNAME If specified, only run benches containing this string in their names
-h, --help Print this message
--lib Benchmark only this package's library
--bin NAME ... Benchmark only the specified binary
--bins Benchmark all binaries
--example NAME ... Benchmark only the specified example
--examples Benchmark all examples
--test NAME ... Benchmark only the specified test target
--tests Benchmark all tests
--bench NAME ... Benchmark only the specified bench target
--benches Benchmark all benches
--all-targets Benchmark all targets (default)
--no-run Compile, but don't run benchmarks
-p SPEC, --package SPEC ... Package to run benchmarks for
--all Benchmark all packages in the workspace
--exclude SPEC ... Exclude packages from the benchmark
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build benchmarks for
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--no-fail-fast Run all benchmarks regardless of failure
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
All of the trailing arguments are passed to the benchmark binaries generated
for filtering benchmarks and generally providing options configuring how they
run.
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be benchmarked. If it is not given, then
the current package is benchmarked. For more information on SPEC and its format,
see the `cargo help pkgid` command.
All packages in the workspace are benchmarked if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.
The --jobs argument affects the building of the benchmark executable but does
not affect how many jobs are used when running the benchmarks.
Compilation can be customized with the `bench` profile in the manifest.
";
pub fn execute(mut options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-bench; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
let spec = Packages::from_flags(options.flag_all,
&options.flag_exclude,
&options.flag_package)?;
let ops = ops::TestOptions {
no_run: options.flag_no_run,
no_fail_fast: options.flag_no_fail_fast,
only_doc: false,
compile_opts: ops::CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec,
release: true,
mode: ops::CompileMode::Bench,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin, options.flag_bins,
&options.flag_test, options.flag_tests,
&options.flag_example, options.flag_examples,
&options.flag_bench, options.flag_benches,
options.flag_all_targets),
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: None,
},
};
if let Some(test) = options.arg_benchname.take() {
options.arg_args.insert(0, test);
}
let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
match err {
None => Ok(()),
Some(err) => {
Err(match err.exit.as_ref().and_then(|e| e.code()) {
Some(i) => CliError::new(format_err!("bench failed"), i),
None => CliError::new(err.into(), 101)
})
}
}
}

View File

@ -1,133 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops::{self, CompileOptions, MessageFormat, Packages};
use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options {
flag_package: Vec<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_release: bool,
flag_lib: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_example: Vec<String>,
flag_examples: bool,
flag_test: Vec<String>,
flag_tests: bool,
flag_bench: Vec<String>,
flag_benches: bool,
flag_all_targets: bool,
flag_locked: bool,
flag_frozen: bool,
flag_all: bool,
flag_exclude: Vec<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Compile a local package and all of its dependencies
Usage:
cargo build [options]
Options:
-h, --help Print this message
-p SPEC, --package SPEC ... Package to build
--all Build all packages in the workspace
--exclude SPEC ... Exclude packages from the build
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--lib Build only this package's library
--bin NAME Build only the specified binary
--bins Build all binaries
--example NAME Build only the specified example
--examples Build all examples
--test NAME Build only the specified test target
--tests Build all tests
--bench NAME Build only the specified bench target
--benches Build all benches
--all-targets Build all targets (lib and bin targets by default)
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to compile
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be built. If it is not given, then the
current package is built. For more information on SPEC and its format, see the
`cargo help pkgid` command.
All packages in the workspace are built if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.
Compilation can be configured via the use of profiles which are configured in
the manifest. The default profile for this command is `dev`, but passing
the --release flag will use the `release` profile instead.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-build; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let mut ws = Workspace::new(&root, config)?;
if config.cli_unstable().avoid_dev_deps {
ws.set_require_optional_deps(false);
}
let spec = Packages::from_flags(options.flag_all,
&options.flag_exclude,
&options.flag_package)?;
let opts = CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec,
mode: ops::CompileMode::Build,
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin, options.flag_bins,
&options.flag_test, options.flag_tests,
&options.flag_example, options.flag_examples,
&options.flag_bench, options.flag_benches,
options.flag_all_targets),
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: None,
};
ops::compile(&ws, &opts)?;
Ok(())
}

View File

@ -88,31 +88,7 @@ fn main() {
}
};
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" | "run" |
"rustc" | "rustdoc" | "search" | "test" | "uninstall" | "update" |
"verify-project" | "version" | "yank" => true,
_ => false
});
let result = if is_clapified {
cli::do_main(&mut config)
} else {
(|| {
let args: Vec<_> = try!(env::args_os()
.map(|s| {
s.into_string().map_err(|s| {
format_err!("invalid unicode in argument: {:?}", s)
})
})
.collect());
let rest = &args;
cargo::call_main_without_stdin(execute, &mut config, USAGE, rest, true)
})()
};
let result = cli::do_main(&mut config);
match result {
Err(e) => cargo::exit_with_error(e, &mut *config.shell()),
Ok(()) => {}
@ -121,36 +97,6 @@ fn main() {
macro_rules! each_subcommand{
($mac:ident) => {
// $mac!(bench);
// $mac!(build);
// $mac!(check);
// $mac!(clean);
// $mac!(doc);
// $mac!(fetch);
// $mac!(generate_lockfile);
// $mac!(git_checkout);
$mac!(help);
// $mac!(init);
// $mac!(install);
// $mac!(locate_project);
// $mac!(login);
// $mac!(metadata);
// $mac!(new);
// $mac!(owner);
// $mac!(package);
// $mac!(pkgid);
// $mac!(publish);
// $mac!(read_manifest);
// $mac!(run);
// $mac!(rustc);
// $mac!(rustdoc);
// $mac!(search);
// $mac!(test);
// $mac!(uninstall);
// $mac!(update);
// $mac!(verify_project);
// $mac!(version);
// $mac!(yank);
}
}

View File

@ -1,146 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops::{self, CompileOptions, MessageFormat, Packages};
use cargo::util::{CliResult, CliError, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
pub const USAGE: &'static str = "
Check a local package and all of its dependencies for errors
Usage:
cargo check [options]
Options:
-h, --help Print this message
-p SPEC, --package SPEC ... Package(s) to check
--all Check all packages in the workspace
--exclude SPEC ... Exclude packages from the check
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--lib Check only this package's library
--bin NAME Check only the specified binary
--bins Check all binaries
--example NAME Check only the specified example
--examples Check all examples
--test NAME Check only the specified test target
--tests Check all tests
--bench NAME Check only the specified bench target
--benches Check all benches
--all-targets Check all targets (lib and bin targets by default)
--release Check artifacts in release mode, with optimizations
--profile PROFILE Profile to build the selected target for
--features FEATURES Space-separated list of features to also check
--all-features Check all available features
--no-default-features Do not check the `default` feature
--target TRIPLE Check for the target triple
--manifest-path PATH Path to the manifest to compile
-v, --verbose ... Use verbose output
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be built. If it is not given, then the
current package is built. For more information on SPEC and its format, see the
`cargo help pkgid` command.
All packages in the workspace are checked if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.
Compilation can be configured via the use of profiles which are configured in
the manifest. The default profile for this command is `dev`, but passing
the --release flag will use the `release` profile instead.
The `--profile test` flag can be used to check unit tests with the
`#[cfg(test)]` attribute.
";
#[derive(Deserialize)]
pub struct Options {
flag_package: Vec<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_release: bool,
flag_lib: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_example: Vec<String>,
flag_examples: bool,
flag_test: Vec<String>,
flag_tests: bool,
flag_bench: Vec<String>,
flag_benches: bool,
flag_all_targets: bool,
flag_locked: bool,
flag_frozen: bool,
flag_all: bool,
flag_exclude: Vec<String>,
flag_profile: Option<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-check; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
let spec = Packages::from_flags(options.flag_all,
&options.flag_exclude,
&options.flag_package)?;
let test = match options.flag_profile.as_ref().map(|t| &t[..]) {
Some("test") => true,
None => false,
Some(profile) => {
let err = format_err!("unknown profile: `{}`, only `test` is \
currently supported", profile);
return Err(CliError::new(err, 101))
}
};
let opts = CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec,
mode: ops::CompileMode::Check{test },
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin, options.flag_bins,
&options.flag_test, options.flag_tests,
&options.flag_example, options.flag_examples,
&options.flag_bench, options.flag_benches,
options.flag_all_targets),
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: None,
};
ops::compile(&ws, &opts)?;
Ok(())
}

View File

@ -1,67 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct Options {
flag_package: Vec<String>,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_release: bool,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Remove artifacts that cargo has generated in the past
Usage:
cargo clean [options]
Options:
-h, --help Print this message
-p SPEC, --package SPEC ... Package to clean artifacts for
--manifest-path PATH Path to the manifest to the package to clean
--target TRIPLE Target triple to clean output for (default all)
--release Whether or not to clean release artifacts
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
If the --package argument is given, then SPEC is a package id specification
which indicates which package's artifacts should be cleaned out. If it is not
given, then all packages' artifacts are removed. For more information on SPEC
and its format, see the `cargo help pkgid` command.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let opts = ops::CleanOptions {
config,
spec: &options.flag_package,
target: options.flag_target.as_ref().map(|s| &s[..]),
release: options.flag_release,
};
let ws = Workspace::new(&root, config)?;
ops::clean(&ws, &opts)?;
Ok(())
}

View File

@ -227,6 +227,9 @@ about this warning.";
}
("build", Some(args)) => {
let ws = workspace_from_args(config, args)?;
if config.cli_unstable().avoid_dev_deps {
ws.set_require_optional_deps(false);
}
let compile_opts = compile_options_from_args(config, args, CompileMode::Build)?;
ops::compile(&ws, &compile_opts)?;
return Ok(());

View File

@ -1,126 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct Options {
flag_target: Option<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_no_deps: bool,
flag_open: bool,
flag_release: bool,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_package: Vec<String>,
flag_lib: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_frozen: bool,
flag_locked: bool,
flag_all: bool,
flag_exclude: Vec<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Build a package's documentation
Usage:
cargo doc [options]
Options:
-h, --help Print this message
--open Opens the docs in a browser after the operation
-p SPEC, --package SPEC ... Package to document
--all Document all packages in the workspace
--exclude SPEC ... Exclude packages from the build
--no-deps Don't build documentation for dependencies
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--lib Document only this package's library
--bin NAME Document only the specified binary
--bins Document all binaries
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to document
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
By default the documentation for the local package and all dependencies is
built. The output is all placed in `target/doc` in rustdoc's usual format.
All packages in the workspace are documented if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be documented. If it is not given, then the
current package is documented. For more information on SPEC and its format, see
the `cargo help pkgid` command.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-check; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
let spec = Packages::from_flags(options.flag_all,
&options.flag_exclude,
&options.flag_package)?;
let empty = Vec::new();
let doc_opts = ops::DocOptions {
open_result: options.flag_open,
compile_opts: ops::CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin, options.flag_bins,
&empty, false,
&empty, false,
&empty, false,
false),
message_format: options.flag_message_format,
release: options.flag_release,
mode: ops::CompileMode::Doc {
deps: !options.flag_no_deps,
},
target_rustc_args: None,
target_rustdoc_args: None,
},
};
ops::doc(&ws, &doc_opts)?;
Ok(())
}

View File

@ -1,56 +0,0 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(Deserialize)]
pub struct Options {
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Fetch dependencies of a package from the network.
Usage:
cargo fetch [options]
Options:
-h, --help Print this message
--manifest-path PATH Path to the manifest to fetch dependencies for
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
If a lockfile is available, this command will ensure that all of the git
dependencies and/or registries dependencies are downloaded and locally
available. The network is never touched after a `cargo fetch` unless
the lockfile changes.
If the lockfile is not available, then this is the equivalent of
`cargo generate-lockfile`. A lockfile is generated and dependencies are also
all updated.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
ops::fetch(&ws)?;
Ok(())
}

View File

@ -1,50 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(Deserialize)]
pub struct Options {
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Generate the lockfile for a project
Usage:
cargo generate-lockfile [options]
Options:
-h, --help Print this message
--manifest-path PATH Path to the manifest to generate a lockfile for
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
ops::generate_lockfile(&ws)?;
Ok(())
}

View File

@ -1,54 +0,0 @@
use cargo::core::source::{Source, SourceId, GitReference};
use cargo::sources::git::{GitSource};
use cargo::util::{Config, CliResult, ToUrl};
#[derive(Deserialize)]
pub struct Options {
flag_url: String,
flag_reference: String,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Checkout a copy of a Git repository
Usage:
cargo git-checkout [options] --url=URL --reference=REF
cargo git-checkout -h | --help
Options:
-h, --help Print this message
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let Options { flag_url: url, flag_reference: reference, .. } = options;
let url = url.to_url()?;
let reference = GitReference::Branch(reference.clone());
let source_id = SourceId::for_git(&url, reference)?;
let mut source = GitSource::new(&source_id, config)?;
source.update()?;
Ok(())
}

View File

@ -1,23 +0,0 @@
use cargo::util::{CliResult, CliError, Config};
#[derive(Deserialize)]
pub struct Options;
pub const USAGE: &'static str = "
Get some help with a cargo command.
Usage:
cargo help <command>
cargo help -h | --help
Options:
-h, --help Print this message
";
pub fn execute(_: Options, _: &mut Config) -> CliResult {
// This is a dummy command just so that `cargo help help` works.
// The actual delegation of help flag to subcommands is handled by the
// cargo command.
Err(CliError::new(format_err!("help command should not be executed directly"),
101))
}

View File

@ -1,70 +0,0 @@
use std::env;
use cargo::ops;
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options {
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_bin: bool,
flag_lib: bool,
arg_path: Option<String>,
flag_name: Option<String>,
flag_vcs: Option<ops::VersionControl>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Create a new cargo package in an existing directory
Usage:
cargo init [options] [<path>]
cargo init -h | --help
Options:
-h, --help Print this message
--vcs VCS Initialize a new repository for the given version
control system (git, hg, pijul, or fossil) or do not
initialize any version control at all (none), overriding
a global configuration.
--bin Use a binary (application) template [default]
--lib Use a library template
--name NAME Set the resulting package name
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-init; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options;
let path = &arg_path.unwrap_or_else(|| String::from("."));
let opts = ops::NewOptions::new(flag_vcs,
flag_bin,
flag_lib,
path,
flag_name.as_ref().map(|s| s.as_ref()))?;
ops::init(&opts, config)?;
config.shell().status("Created", format!("{} project", opts.kind))?;
Ok(())
}

View File

@ -1,175 +0,0 @@
use cargo::ops;
use cargo::core::{SourceId, GitReference};
use cargo::util::{CliResult, Config, ToUrl};
#[derive(Deserialize)]
pub struct Options {
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_debug: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_example: Vec<String>,
flag_examples: bool,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_root: Option<String>,
flag_list: bool,
flag_force: bool,
flag_frozen: bool,
flag_locked: bool,
arg_crate: Vec<String>,
flag_vers: Option<String>,
flag_version: Option<String>,
flag_git: Option<String>,
flag_branch: Option<String>,
flag_tag: Option<String>,
flag_rev: Option<String>,
flag_path: Option<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Install a Rust binary
Usage:
cargo install [options] [<crate>...]
cargo install [options] --list
Specifying what crate to install:
--vers VERSION Specify a version to install from crates.io
--version VERSION
--git URL Git URL to install the specified crate from
--branch BRANCH Branch to use when installing from git
--tag TAG Tag to use when installing from git
--rev SHA Specific commit to use when installing from git
--path PATH Filesystem path to local crate to install
Build and install options:
-h, --help Print this message
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
-f, --force Force overwriting existing crates or binaries
--features FEATURES Space-separated list of features to activate
--all-features Build all available features
--no-default-features Do not build the `default` feature
--debug Build in debug mode instead of release mode
--bin NAME Install only the specified binary
--bins Install all binaries
--example NAME Install only the specified example
--examples Install all examples
--root DIR Directory to install packages into
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet Less output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
This command manages Cargo's local set of installed binary crates. Only packages
which have [[bin]] targets can be installed, and all binaries are installed into
the installation root's `bin` folder. The installation root is determined, in
order of precedence, by `--root`, `$CARGO_INSTALL_ROOT`, the `install.root`
configuration key, and finally the home directory (which is either
`$CARGO_HOME` if set or `$HOME/.cargo` by default).
There are multiple sources from which a crate can be installed. The default
location is crates.io but the `--git` and `--path` flags can change this source.
If the source contains more than one package (such as crates.io or a git
repository with multiple crates) the `<crate>` argument is required to indicate
which crate should be installed.
Crates from crates.io can optionally specify the version they wish to install
via the `--vers` flags, and similarly packages from git repositories can
optionally specify the branch, tag, or revision that should be installed. If a
crate has multiple binaries, the `--bin` argument can selectively install only
one of them, and if you'd rather install examples the `--example` argument can
be used as well.
By default cargo will refuse to overwrite existing binaries. The `--force` flag
enables overwriting existing binaries. Thus you can reinstall a crate with
`cargo install --force <crate>`.
As a special convenience, omitting the <crate> specification entirely will
install the crate in the current directory. That is, `install` is equivalent to
the more explicit `install --path .`.
If the source is crates.io or `--git` then by default the crate will be built
in a temporary target directory. To avoid this, the target directory can be
specified by setting the `CARGO_TARGET_DIR` environment variable to a relative
path. In particular, this can be useful for caching build artifacts on
continuous integration systems.
The `--list` option will list all installed packages (and their versions).
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let compile_opts = ops::CompileOptions {
config,
jobs: options.flag_jobs,
target: None,
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: ops::Packages::Packages(&[]),
mode: ops::CompileMode::Build,
release: !options.flag_debug,
filter: ops::CompileFilter::new(false,
&options.flag_bin, options.flag_bins,
&[], false,
&options.flag_example, options.flag_examples,
&[], false,
false),
message_format: ops::MessageFormat::Human,
target_rustc_args: None,
target_rustdoc_args: None,
};
let source = if let Some(url) = options.flag_git {
let url = url.to_url()?;
let gitref = if let Some(branch) = options.flag_branch {
GitReference::Branch(branch)
} else if let Some(tag) = options.flag_tag {
GitReference::Tag(tag)
} else if let Some(rev) = options.flag_rev {
GitReference::Rev(rev)
} else {
GitReference::Branch("master".to_string())
};
SourceId::for_git(&url, gitref)?
} else if let Some(path) = options.flag_path {
SourceId::for_path(&config.cwd().join(path))?
} else if options.arg_crate.is_empty() {
SourceId::for_path(config.cwd())?
} else {
SourceId::crates_io(config)?
};
let krates = options.arg_crate.iter().map(|s| &s[..]).collect::<Vec<_>>();
let vers = match (&options.flag_vers, &options.flag_version) {
(&Some(_), &Some(_)) => return Err(format_err!("invalid arguments").into()),
(&Some(ref v), _) | (_, &Some(ref v)) => Some(v.as_ref()),
_ => None,
};
let root = options.flag_root.as_ref().map(|s| &s[..]);
if options.flag_list {
ops::install_list(root, config)?;
} else {
ops::install(root, krates, &source, vers, &compile_opts, options.flag_force)?;
}
Ok(())
}

View File

@ -1,38 +0,0 @@
use cargo;
use cargo::util::{CliResult, CliError, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct LocateProjectFlags {
flag_manifest_path: Option<String>,
}
pub const USAGE: &'static str = "
Print a JSON representation of a Cargo.toml file's location
Usage:
cargo locate-project [options]
Options:
--manifest-path PATH Path to the manifest to locate
-h, --help Print this message
";
#[derive(Serialize)]
pub struct ProjectLocation {
root: String
}
pub fn execute(flags: LocateProjectFlags, config: &mut Config) -> CliResult {
let root = find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd())?;
let string = root.to_str()
.ok_or_else(|| format_err!("your project path contains \
characters not representable in \
Unicode"))
.map_err(|e| CliError::new(e, 1))?;
let location = ProjectLocation { root: string.to_string() };
cargo::print_json(&location);
Ok(())
}

View File

@ -1,83 +0,0 @@
use std::io::prelude::*;
use std::io;
use cargo::ops;
use cargo::core::{SourceId, Source};
use cargo::sources::RegistrySource;
use cargo::util::{CliResult, CargoResultExt, Config, CargoError};
#[derive(Deserialize)]
pub struct Options {
flag_host: Option<String>,
arg_token: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
flag_registry: Option<String>,
}
pub const USAGE: &'static str = "
Save an api token from the registry locally. If token is not specified, it will be read from stdin.
Usage:
cargo login [options] [<token>]
Options:
-h, --help Print this message
--host HOST Host to set the token for
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
--registry REGISTRY Registry to use
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
if options.flag_registry.is_some() && !config.cli_unstable().unstable_options {
return Err(format_err!("registry option is an unstable feature and \
requires -Zunstable-options to use.").into());
}
let token = match options.arg_token {
Some(token) => token,
None => {
let host = match options.flag_registry {
Some(ref _registry) => {
return Err(format_err!("token must be provided when \
--registry is provided.").into())
}
None => {
let src = SourceId::crates_io(config)?;
let mut src = RegistrySource::remote(&src, config);
src.update()?;
let config = src.config()?.unwrap();
options.flag_host.clone().unwrap_or(config.api.unwrap())
}
};
println!("please visit {}me and paste the API Token below", host);
let mut line = String::new();
let input = io::stdin();
input.lock().read_line(&mut line).chain_err(|| {
"failed to read stdin"
}).map_err(CargoError::from)?;
line.trim().to_string()
}
};
ops::registry_login(config, token, options.flag_registry)?;
Ok(())
}

View File

@ -1,75 +0,0 @@
use cargo;
use cargo::core::Workspace;
use cargo::ops::{output_metadata, OutputMetadataOptions};
use cargo::util::important_paths::find_root_manifest_for_wd;
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options {
flag_color: Option<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_format_version: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_no_deps: bool,
flag_quiet: Option<bool>,
flag_verbose: u32,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Output the resolved dependencies of a project, the concrete used versions
including overrides, in machine-readable format.
Usage:
cargo metadata [options]
Options:
-h, --help Print this message
--features FEATURES Space-separated list of features
--all-features Build all available features
--no-default-features Do not include the `default` feature
--no-deps Output information only about the root package
and don't fetch dependencies.
--manifest-path PATH Path to the manifest
--format-version VERSION Format version
Valid values: 1
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let manifest = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
if options.flag_format_version.is_none() {
config.shell().warn("please specify `--format-version` flag explicitly to \
avoid compatibility problems")?
}
let options = OutputMetadataOptions {
features: options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
no_deps: options.flag_no_deps,
version: options.flag_format_version.unwrap_or(1),
};
let ws = Workspace::new(&manifest, config)?;
let result = output_metadata(&ws, &options)?;
cargo::print_json(&result);
Ok(())
}

View File

@ -1,69 +0,0 @@
use std::env;
use cargo::ops;
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options {
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_bin: bool,
flag_lib: bool,
arg_path: String,
flag_name: Option<String>,
flag_vcs: Option<ops::VersionControl>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Create a new cargo package at <path>
Usage:
cargo new [options] <path>
cargo new -h | --help
Options:
-h, --help Print this message
--vcs VCS Initialize a new repository for the given version
control system (git, hg, pijul, or fossil) or do not
initialize any version control at all (none), overriding
a global configuration.
--bin Use a binary (application) template [default]
--lib Use a library template
--name NAME Set the resulting package name, defaults to the value of <path>
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options;
let opts = ops::NewOptions::new(flag_vcs,
flag_bin,
flag_lib,
&arg_path,
flag_name.as_ref().map(|s| s.as_ref()))?;
ops::new(&opts, config)?;
config.shell().status("Created", format!("{} `{}` project", opts.kind, arg_path))?;
Ok(())
}

View File

@ -1,77 +0,0 @@
use cargo::ops;
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options {
arg_crate: Option<String>,
flag_token: Option<String>,
flag_add: Option<Vec<String>>,
flag_remove: Option<Vec<String>>,
flag_index: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_list: bool,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
flag_registry: Option<String>,
}
pub const USAGE: &'static str = "
Manage the owners of a crate on the registry
Usage:
cargo owner [options] [<crate>]
Options:
-h, --help Print this message
-a, --add LOGIN Name of a user or team to add as an owner
-r, --remove LOGIN Name of a user or team to remove as an owner
-l, --list List owners of a crate
--index INDEX Registry index to modify owners for
--token TOKEN API token to use when authenticating
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
--registry REGISTRY Registry to use
This command will modify the owners for a package on the specified registry (or
default). Note that owners of a package can upload new versions, yank old
versions. Explicitly named owners can also modify the set of owners, so take
caution!
See http://doc.crates.io/crates-io.html#cargo-owner for detailed documentation
and troubleshooting.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let opts = ops::OwnersOptions {
krate: options.arg_crate,
token: options.flag_token,
index: options.flag_index,
to_add: options.flag_add,
to_remove: options.flag_remove,
list: options.flag_list,
registry: options.flag_registry,
};
if opts.registry.is_some() && !config.cli_unstable().unstable_options {
return Err(format_err!("registry option is an unstable feature and \
requires -Zunstable-options to use.").into())
}
ops::modify_owners(config, &opts)?;
Ok(())
}

View File

@ -1,67 +0,0 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(Deserialize)]
pub struct Options {
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_no_verify: bool,
flag_no_metadata: bool,
flag_list: bool,
flag_allow_dirty: bool,
flag_jobs: Option<u32>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Assemble the local package into a distributable tarball
Usage:
cargo package [options]
Options:
-h, --help Print this message
-l, --list Print files included in a package without making one
--no-verify Don't verify the contents by building them
--no-metadata Ignore warnings about a lack of human-usable metadata
--allow-dirty Allow dirty working directories to be packaged
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to compile
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
ops::package(&ws, &ops::PackageOpts {
config,
verify: !options.flag_no_verify,
list: options.flag_list,
check_metadata: !options.flag_no_metadata,
allow_dirty: options.flag_allow_dirty,
target: options.flag_target.as_ref().map(|t| &t[..]),
jobs: options.flag_jobs,
registry: None,
})?;
Ok(())
}

View File

@ -1,80 +0,0 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct Options {
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_manifest_path: Option<String>,
flag_frozen: bool,
flag_locked: bool,
flag_package: Option<String>,
arg_spec: Option<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Print a fully qualified package specification
Usage:
cargo pkgid [options] [<spec>]
Options:
-h, --help Print this message
-p SPEC, --package SPEC Argument to get the package id specifier for
--manifest-path PATH Path to the manifest to the package to clean
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
Given a <spec> argument, print out the fully qualified package id specifier.
This command will generate an error if <spec> is ambiguous as to which package
it refers to in the dependency graph. If no <spec> is given, then the pkgid for
the local package is printed.
This command requires that a lockfile is available and dependencies have been
fetched.
Example Package IDs
pkgid | name | version | url
|-----------------------------|--------|-----------|---------------------|
foo | foo | * | *
foo:1.2.3 | foo | 1.2.3 | *
crates.io/foo | foo | * | *://crates.io/foo
crates.io/foo#1.2.3 | foo | 1.2.3 | *://crates.io/foo
crates.io/bar#foo:1.2.3 | foo | 1.2.3 | *://crates.io/bar
http://crates.io/foo#1.2.3 | foo | 1.2.3 | http://crates.io/foo
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd())?;
let ws = Workspace::new(&root, config)?;
let spec = if options.arg_spec.is_some() {
options.arg_spec
} else if options.flag_package.is_some() {
options.flag_package
} else {
None
};
let spec = spec.as_ref().map(|s| &s[..]);
let spec = ops::pkgid(&ws, spec)?;
println!("{}", spec);
Ok(())
}

View File

@ -1,113 +0,0 @@
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(Deserialize)]
pub struct Options {
flag_index: Option<String>,
flag_host: Option<String>, // TODO: Deprecated, remove
flag_token: Option<String>,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_no_verify: bool,
flag_allow_dirty: bool,
flag_jobs: Option<u32>,
flag_dry_run: bool,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
flag_registry: Option<String>,
}
pub const USAGE: &'static str = "
Upload a package to the registry
Usage:
cargo publish [options]
Options:
-h, --help Print this message
--index INDEX Registry index to upload the package to
--host HOST DEPRECATED, renamed to '--index'
--token TOKEN Token to use when uploading
--no-verify Don't verify package tarball before publish
--allow-dirty Allow publishing with a dirty source directory
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest of the package to publish
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--dry-run Perform all checks without uploading
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
--registry REGISTRY Registry to publish to
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let Options {
flag_token: token,
flag_index: index,
flag_host: host, // TODO: Deprecated, remove
flag_manifest_path,
flag_no_verify: no_verify,
flag_allow_dirty: allow_dirty,
flag_jobs: jobs,
flag_dry_run: dry_run,
flag_target: target,
flag_registry: registry,
..
} = options;
if registry.is_some() && !config.cli_unstable().unstable_options {
return Err(format_err!("registry option is an unstable feature and \
requires -Zunstable-options to use.").into())
}
// TODO: Deprecated
// remove once it has been decided --host can be removed
// We may instead want to repurpose the host flag, as
// mentioned in this issue
// https://github.com/rust-lang/cargo/issues/4208
let msg = "The flag '--host' is no longer valid.
Previous versions of Cargo accepted this flag, but it is being
deprecated. The flag is being renamed to 'index', as the flag
wants the location of the index to which to publish. Please
use '--index' instead.
This will soon become a hard error, so it's either recommended
to update to a fixed version or contact the upstream maintainer
about this warning.";
let root = find_root_manifest_for_wd(flag_manifest_path.clone(), config.cwd())?;
let ws = Workspace::new(&root, config)?;
ops::publish(&ws, &ops::PublishOpts {
config,
token,
index:
if host.clone().is_none() || host.clone().unwrap().is_empty() { index }
else { config.shell().warn(&msg)?; host }, // TODO: Deprecated, remove
verify: !no_verify,
allow_dirty,
target: target.as_ref().map(|t| &t[..]),
jobs,
dry_run,
registry,
})?;
Ok(())
}

View File

@ -1,39 +0,0 @@
use std::env;
use cargo;
use cargo::core::Package;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct Options {
flag_manifest_path: Option<String>,
flag_color: Option<String>,
}
pub const USAGE: &'static str = "
Deprecated, use `cargo metadata --no-deps` instead.
Print a JSON representation of a Cargo.toml manifest.
Usage:
cargo read-manifest [options]
cargo read-manifest -h | --help
Options:
-h, --help Print this message
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
--manifest-path PATH Path to the manifest
--color WHEN Coloring: auto, always, never
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-read-manifest; args={:?}",
env::args().collect::<Vec<_>>());
config.shell().set_color_choice(options.flag_color.as_ref().map(|s| &s[..]))?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let pkg = Package::for_path(&root, config)?;
cargo::print_json(&pkg);
Ok(())
}

View File

@ -1,135 +0,0 @@
use std::iter::FromIterator;
use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, CliError, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct Options {
flag_bin: Option<String>,
flag_example: Option<String>,
flag_package: Option<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_release: bool,
flag_frozen: bool,
flag_locked: bool,
arg_args: Vec<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Run the main binary of the local package (src/main.rs)
Usage:
cargo run [options] [--] [<args>...]
Options:
-h, --help Print this message
--bin NAME Name of the bin target to run
--example NAME Name of the example target to run
-p SPEC, --package SPEC Package with the target to run
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to execute
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
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.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let (mut examples, mut bins) = (Vec::new(), Vec::new());
if let Some(s) = options.flag_bin {
bins.push(s);
}
if let Some(s) = options.flag_example {
examples.push(s);
}
let packages = Vec::from_iter(options.flag_package.iter().cloned());
let spec = Packages::Packages(&packages);
let compile_opts = ops::CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec,
release: options.flag_release,
mode: ops::CompileMode::Build,
filter: if examples.is_empty() && bins.is_empty() {
ops::CompileFilter::Default { required_features_filterable: false, }
} else {
ops::CompileFilter::new(false,
&bins, false,
&[], false,
&examples, false,
&[], false,
false)
},
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: None,
};
let ws = Workspace::new(&root, config)?;
match ops::run(&ws, &compile_opts, &options.arg_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 options.flag_quiet == Some(true) {
CliError::code(exit_code)
} else {
CliError::new(err.into(), exit_code)
})
}
}
}

View File

@ -1,140 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops::{self, CompileOptions, CompileMode, MessageFormat, Packages};
use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, CliError, Config};
#[derive(Deserialize)]
pub struct Options {
arg_opts: Option<Vec<String>>,
flag_package: Option<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_release: bool,
flag_lib: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_example: Vec<String>,
flag_examples: bool,
flag_test: Vec<String>,
flag_tests: bool,
flag_bench: Vec<String>,
flag_benches: bool,
flag_all_targets: bool,
flag_profile: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Compile a package and all of its dependencies
Usage:
cargo rustc [options] [--] [<opts>...]
Options:
-h, --help Print this message
-p SPEC, --package SPEC Package to build
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--lib Build only this package's library
--bin NAME Build only the specified binary
--bins Build all binaries
--example NAME Build only the specified example
--examples Build all examples
--test NAME Build only the specified test target
--tests Build all tests
--bench NAME Build only the specified bench target
--benches Build all benches
--all-targets Build all targets (lib and bin targets by default)
--release Build artifacts in release mode, with optimizations
--profile PROFILE Profile to build the selected target for
--features FEATURES Features to compile for the package
--all-features Build all available features
--no-default-features Do not compile default features for the package
--target TRIPLE Target triple which compiles will be for
--manifest-path PATH Path to the manifest to fetch dependencies for
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
The specified target for the current package (or package specified by SPEC if
provided) will be compiled along with all of its dependencies. The specified
<opts>... will all be passed to the final compiler invocation, not any of the
dependencies. Note that the compiler will still unconditionally receive
arguments such as -L, --extern, and --crate-type, and the specified <opts>...
will simply be added to the compiler invocation.
This command requires that only one target is being compiled. If more than one
target is available for the current package the filters of --lib, --bin, etc,
must be used to select which target is compiled. To pass flags to all compiler
processes spawned by Cargo, use the $RUSTFLAGS environment variable or the
`build.rustflags` configuration option.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-rustc; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path,
config.cwd())?;
let mode = match options.flag_profile.as_ref().map(|t| &t[..]) {
Some("dev") | None => CompileMode::Build,
Some("test") => CompileMode::Test,
Some("bench") => CompileMode::Bench,
Some("check") => CompileMode::Check {test: false},
Some(mode) => {
let err = format_err!("unknown profile: `{}`, use dev,
test, or bench", mode);
return Err(CliError::new(err, 101))
}
};
let spec = options.flag_package.map_or_else(Vec::new, |s| vec![s]);
let opts = CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: Packages::Packages(&spec),
mode,
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin, options.flag_bins,
&options.flag_test, options.flag_tests,
&options.flag_example, options.flag_examples,
&options.flag_bench, options.flag_benches,
options.flag_all_targets),
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
};
let ws = Workspace::new(&root, config)?;
ops::compile(&ws, &opts)?;
Ok(())
}

View File

@ -1,127 +0,0 @@
use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::{find_root_manifest_for_wd};
#[derive(Deserialize)]
pub struct Options {
arg_opts: Vec<String>,
flag_target: Option<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_open: bool,
flag_verbose: u32,
flag_release: bool,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_package: Option<String>,
flag_lib: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_example: Vec<String>,
flag_examples: bool,
flag_test: Vec<String>,
flag_tests: bool,
flag_bench: Vec<String>,
flag_benches: bool,
flag_all_targets: bool,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Build a package's documentation, using specified custom flags.
Usage:
cargo rustdoc [options] [--] [<opts>...]
Options:
-h, --help Print this message
--open Opens the docs in a browser after the operation
-p SPEC, --package SPEC Package to document
-j N, --jobs N Number of parallel jobs, defaults to # of CPUs
--lib Build only this package's library
--bin NAME Build only the specified binary
--bins Build all binaries
--example NAME Build only the specified example
--examples Build all examples
--test NAME Build only the specified test target
--tests Build all tests
--bench NAME Build only the specified bench target
--benches Build all benches
--all-targets Build all targets (default)
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to document
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
The specified target for the current package (or package specified by SPEC if
provided) will be documented with the specified <opts>... being passed to the
final rustdoc invocation. Dependencies will not be documented as part of this
command. Note that rustdoc will still unconditionally receive arguments such
as -L, --extern, and --crate-type, and the specified <opts>... will simply be
added to the rustdoc invocation.
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be documented. If it is not given, then the
current package is documented. For more information on SPEC and its format, see
the `cargo help pkgid` command.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path,
config.cwd())?;
let spec = options.flag_package.map_or_else(Vec::new, |s| vec![s]);
let doc_opts = ops::DocOptions {
open_result: options.flag_open,
compile_opts: ops::CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|t| &t[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec: Packages::Packages(&spec),
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin, options.flag_bins,
&options.flag_test, options.flag_tests,
&options.flag_example, options.flag_examples,
&options.flag_bench, options.flag_benches,
options.flag_all_targets),
message_format: options.flag_message_format,
mode: ops::CompileMode::Doc { deps: false },
target_rustdoc_args: Some(&options.arg_opts),
target_rustc_args: None,
},
};
let ws = Workspace::new(&root, config)?;
ops::doc(&ws, &doc_opts)?;
Ok(())
}

View File

@ -1,90 +0,0 @@
use cargo::ops;
use cargo::util::{CliResult, Config};
use std::cmp;
#[derive(Deserialize)]
pub struct Options {
flag_index: Option<String>,
flag_host: Option<String>, // TODO: Deprecated, remove
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_limit: Option<u32>,
flag_frozen: bool,
flag_locked: bool,
arg_query: Vec<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
flag_registry: Option<String>,
}
pub const USAGE: &'static str = "
Search packages in crates.io
Usage:
cargo search [options] <query>...
cargo search [-h | --help]
Options:
-h, --help Print this message
--index INDEX Registry index to search in
--host HOST DEPRECATED, renamed to '--index'
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--limit LIMIT Limit the number of results (default: 10, max: 100)
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
--registry REGISTRY Registry to use
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let Options {
flag_index: index,
flag_host: host, // TODO: Deprecated, remove
flag_limit: limit,
arg_query: query,
flag_registry: registry,
..
} = options;
if registry.is_some() && !config.cli_unstable().unstable_options {
return Err(format_err!("registry option is an unstable feature and \
requires -Zunstable-options to use.").into())
}
// TODO: Deprecated
// remove once it has been decided --host can be safely removed
// We may instead want to repurpose the host flag, as
// mentioned in this issue
// https://github.com/rust-lang/cargo/issues/4208
let msg = "The flag '--host' is no longer valid.
Previous versions of Cargo accepted this flag, but it is being
deprecated. The flag is being renamed to 'index', as the flag
wants the location of the index in which to search. Please
use '--index' instead.
This will soon become a hard error, so it's either recommended
to update to a fixed version or contact the upstream maintainer
about this warning.";
let index = if host.clone().is_none() || host.clone().unwrap().is_empty() {
index
} else {
config.shell().warn(&msg)?;
host
};
ops::search(&query.join("+"), config, index, cmp::min(100, limit.unwrap_or(10)) as u8, registry)?;
Ok(())
}

View File

@ -1,194 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops::{self, MessageFormat, Packages};
use cargo::util::{CliResult, CliError, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(Deserialize)]
pub struct Options {
arg_args: Vec<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_jobs: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_no_run: bool,
flag_package: Vec<String>,
flag_target: Option<String>,
flag_lib: bool,
flag_doc: bool,
flag_bin: Vec<String>,
flag_bins: bool,
flag_example: Vec<String>,
flag_examples: bool,
flag_test: Vec<String>,
flag_tests: bool,
flag_bench: Vec<String>,
flag_benches: bool,
flag_all_targets: bool,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_release: bool,
flag_no_fail_fast: bool,
flag_frozen: bool,
flag_locked: bool,
flag_all: bool,
flag_exclude: Vec<String>,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
#[serde(rename = "arg_TESTNAME")]
arg_testname: Option<String>,
}
pub const USAGE: &'static str = "
Execute all unit and integration tests of a local package
Usage:
cargo test [options] [TESTNAME] [--] [<args>...]
Options:
TESTNAME If specified, only run tests containing this string in their names
-h, --help Print this message
--lib Test only this package's library
--doc Test only this library's documentation
--bin NAME ... Test only the specified binary
--bins Test all binaries
--example NAME ... Check that the specified examples compile
--examples Check that all examples compile
--test NAME ... Test only the specified test target
--tests Test all tests
--bench NAME ... Test only the specified bench target
--benches Test all benches
--all-targets Test all targets (default)
--no-run Compile, but don't run tests
-p SPEC, --package SPEC ... Package to run tests for
--all Test all packages in the workspace
--exclude SPEC ... Exclude packages from the test
-j N, --jobs N Number of parallel builds, see below for details
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
--no-default-features Do not build the `default` feature
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to build tests for
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--no-fail-fast Run all tests regardless of failure
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
All of the trailing arguments are passed to the test binaries generated for
filtering tests and generally providing options configuring how they run. For
example, this will run all tests with the name `foo` in their name:
cargo test foo
If the --package argument is given, then SPEC is a package id specification
which indicates which package should be tested. If it is not given, then the
current package is tested. For more information on SPEC and its format, see the
`cargo help pkgid` command.
All packages in the workspace are tested if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.
The --jobs argument affects the building of the test executable but does
not affect how many jobs are used when running the tests. The default value
for the --jobs argument is the number of CPUs. If you want to control the
number of simultaneous running test cases, pass the `--test-threads` option
to the test binaries:
cargo test -- --test-threads=1
Compilation can be configured via the `test` profile in the manifest.
By default the rust test harness hides output from test execution to
keep results readable. Test output can be recovered (e.g. for debugging)
by passing `--nocapture` to the test binaries:
cargo test -- --nocapture
To get the list of all options available for the test binaries use this:
cargo test -- --help
";
pub fn execute(mut options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-test; args={:?}",
env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let ws = Workspace::new(&root, config)?;
let empty = Vec::new();
let (mode, filter);
if options.flag_doc {
mode = ops::CompileMode::Doctest;
filter = ops::CompileFilter::new(true, &empty, false, &empty, false,
&empty, false, &empty, false,
false);
} else {
mode = ops::CompileMode::Test;
filter = ops::CompileFilter::new(options.flag_lib,
&options.flag_bin, options.flag_bins,
&options.flag_test, options.flag_tests,
&options.flag_example, options.flag_examples,
&options.flag_bench, options.flag_benches,
options.flag_all_targets);
}
let spec = Packages::from_flags(options.flag_all,
&options.flag_exclude,
&options.flag_package)?;
let ops = ops::TestOptions {
no_run: options.flag_no_run,
no_fail_fast: options.flag_no_fail_fast,
only_doc: options.flag_doc,
compile_opts: ops::CompileOptions {
config,
jobs: options.flag_jobs,
target: options.flag_target.as_ref().map(|s| &s[..]),
features: &options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
spec,
release: options.flag_release,
mode,
filter,
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: None,
},
};
// TESTNAME is actually an argument of the test binary, but it's
// important so we explicitly mention it and reconfigure
if let Some(test) = options.arg_testname.take() {
options.arg_args.insert(0, test);
}
let err = ops::run_tests(&ws, &ops, &options.arg_args)?;
match err {
None => Ok(()),
Some(err) => {
Err(match err.exit.as_ref().and_then(|e| e.code()) {
Some(i) => CliError::new(format_err!("{}", err.hint(&ws)), i),
None => CliError::new(err.into(), 101),
})
}
}
}

View File

@ -1,57 +0,0 @@
use cargo::ops;
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options {
flag_bin: Vec<String>,
flag_root: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
arg_spec: Vec<String>,
}
pub const USAGE: &'static str = "
Remove a Rust binary
Usage:
cargo uninstall [options] <spec>...
cargo uninstall (-h | --help)
Options:
-h, --help Print this message
--root DIR Directory to uninstall packages from
--bin NAME Only uninstall the binary NAME
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet Less output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
The argument SPEC is a package id specification (see `cargo help pkgid`) to
specify which crate should be uninstalled. By default all binaries are
uninstalled for a crate but the `--bin` and `--example` flags can be used to
only uninstall particular binaries.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = options.flag_root.as_ref().map(|s| &s[..]);
let specs = options.arg_spec.iter().map(|s| &s[..]).collect::<Vec<_>>();
ops::uninstall(root, specs, &options.flag_bin, config)?;
Ok(())
}

View File

@ -1,83 +0,0 @@
use std::env;
use cargo::core::Workspace;
use cargo::ops;
use cargo::util::{CliResult, Config};
use cargo::util::important_paths::find_root_manifest_for_wd;
#[derive(Deserialize)]
pub struct Options {
flag_package: Vec<String>,
flag_aggressive: bool,
flag_precise: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Update dependencies as recorded in the local lock file.
Usage:
cargo update [options]
Options:
-h, --help Print this message
-p SPEC, --package SPEC ... Package to update
--aggressive Force updating all dependencies of <name> as well
--precise PRECISE Update a single dependency to exactly PRECISE
--manifest-path PATH Path to the crate's manifest
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
This command requires that a `Cargo.lock` already exists as generated by
`cargo build` or related commands.
If SPEC is given, then a conservative update of the lockfile will be
performed. This means that only the dependency specified by SPEC will be
updated. Its transitive dependencies will be updated only if SPEC cannot be
updated without updating dependencies. All other dependencies will remain
locked at their currently recorded versions.
If PRECISE is specified, then --aggressive must not also be specified. The
argument PRECISE is a string representing a precise revision that the package
being updated should be updated to. For example, if the package comes from a git
repository, then PRECISE would be the exact revision that the repository should
be updated to.
If SPEC is not given, then all dependencies will be re-resolved and
updated.
For more information about package id specifications, see `cargo help pkgid`.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
let update_opts = ops::UpdateOptions {
aggressive: options.flag_aggressive,
precise: options.flag_precise.as_ref().map(|s| &s[..]),
to_update: &options.flag_package,
config,
};
let ws = Workspace::new(&root, config)?;
ops::update_lockfile(&ws, &update_opts)?;
Ok(())
}

View File

@ -1,77 +0,0 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::process;
use cargo;
use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, Config};
use serde_json;
use toml;
#[derive(Deserialize)]
pub struct Flags {
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
}
pub const USAGE: &'static str = "
Check correctness of crate manifest
Usage:
cargo verify-project [options]
cargo verify-project -h | --help
Options:
-h, --help Print this message
--manifest-path PATH Path to the manifest to verify
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
";
pub fn execute(args: Flags, config: &mut Config) -> CliResult {
config.configure(args.flag_verbose,
args.flag_quiet,
&args.flag_color,
args.flag_frozen,
args.flag_locked,
&args.flag_z)?;
let mut contents = String::new();
let filename = args.flag_manifest_path.unwrap_or_else(|| "Cargo.toml".into());
let filename = match find_root_manifest_for_wd(Some(filename), config.cwd()) {
Ok(manifest_path) => manifest_path,
Err(e) => fail("invalid", &e.to_string()),
};
let file = File::open(&filename);
match file.and_then(|mut f| f.read_to_string(&mut contents)) {
Ok(_) => {},
Err(e) => fail("invalid", &format!("error reading file: {}", e))
};
if contents.parse::<toml::Value>().is_err() {
fail("invalid", "invalid-format");
}
let mut h = HashMap::new();
h.insert("success".to_string(), "true".to_string());
cargo::print_json(&h);
Ok(())
}
fn fail(reason: &str, value: &str) -> ! {
let mut h = HashMap::new();
h.insert(reason.to_string(), value.to_string());
println!("{}", serde_json::to_string(&h).unwrap());
process::exit(1)
}

View File

@ -1,27 +0,0 @@
use std::env;
use cargo;
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options;
pub const USAGE: &'static str = "
Show version information
Usage:
cargo version [options]
Options:
-h, --help Print this message
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
--color WHEN Coloring: auto, always, never
";
pub fn execute(_: Options, _: &mut Config) -> CliResult {
debug!("executing; cmd=cargo-version; args={:?}", env::args().collect::<Vec<_>>());
println!("{}", cargo::version());
Ok(())
}

View File

@ -1,72 +0,0 @@
use cargo::ops;
use cargo::util::{CliResult, Config};
#[derive(Deserialize)]
pub struct Options {
arg_crate: Option<String>,
flag_token: Option<String>,
flag_vers: Option<String>,
flag_index: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_undo: bool,
flag_frozen: bool,
flag_locked: bool,
#[serde(rename = "flag_Z")]
flag_z: Vec<String>,
flag_registry: Option<String>,
}
pub static USAGE: &'static str = "
Remove a pushed crate from the index
Usage:
cargo yank [options] [<crate>]
Options:
-h, --help Print this message
--vers VERSION The version to yank or un-yank
--undo Undo a yank, putting a version back into the index
--index INDEX Registry index to yank from
--token TOKEN API token to use when authenticating
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z FLAG ... Unstable (nightly-only) flags to Cargo
--registry REGISTRY Registry to use
The yank command removes a previously pushed crate's version from the server's
index. This command does not delete any data, and the crate will still be
available for download via the registry's download link.
Note that existing crates locked to a yanked version will still be able to
download the yanked version to use it. Cargo will, however, not allow any new
crates to be locked to any yanked version.
";
pub fn execute(options: Options, config: &mut Config) -> CliResult {
config.configure(options.flag_verbose,
options.flag_quiet,
&options.flag_color,
options.flag_frozen,
options.flag_locked,
&options.flag_z)?;
if options.flag_registry.is_some() && !config.cli_unstable().unstable_options {
return Err(format_err!("registry option is an unstable feature and \
requires -Zunstable-options to use.").into())
}
ops::yank(config,
options.arg_crate,
options.flag_vers,
options.flag_token,
options.flag_index,
options.flag_undo,
options.flag_registry)?;
Ok(())
}

View File

@ -2,6 +2,7 @@ use cargotest::support::{project, execs, basic_bin_manifest};
use hamcrest::{assert_that};
#[test]
#[ignore]
fn alias_incorrect_config_type() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))

View File

@ -59,6 +59,7 @@ fn path() -> Vec<PathBuf> {
}
#[test]
#[ignore]
fn list_command_looks_at_path() {
let proj = project("list-non-overlapping").build();
let proj = fake_file(proj, Path::new("path-test"), "cargo-1", &FakeKind::Executable);
@ -77,6 +78,7 @@ fn list_command_looks_at_path() {
// windows and symlinks don't currently agree that well
#[cfg(unix)]
#[test]
#[ignore]
fn list_command_resolves_symlinks() {
use cargotest::support::cargo_exe;
@ -112,6 +114,7 @@ fn find_closest_biuld_to_build() {
// if a subcommand is more than 3 edit distance away, we don't make a suggestion
#[test]
#[ignore]
fn find_closest_dont_correct_nonsense() {
let mut pr = cargo_process();
pr.arg("there-is-no-way-that-there-is-a-command-close-to-this")
@ -125,6 +128,7 @@ fn find_closest_dont_correct_nonsense() {
}
#[test]
#[ignore]
fn displays_subcommand_on_error() {
let mut pr = cargo_process();
pr.arg("invalid-command");
@ -160,6 +164,7 @@ fn override_cargo_home() {
}
#[test]
#[ignore]
fn cargo_subcommand_env() {
use cargotest::support::cargo_exe;
@ -192,6 +197,7 @@ fn cargo_subcommand_env() {
}
#[test]
#[ignore]
fn cargo_help() {
assert_that(cargo_process(),
execs().with_status(0));

View File

@ -726,6 +726,7 @@ fn uninstall_piecemeal() {
}
#[test]
#[ignore]
fn subcommand_works_out_of_the_box() {
Package::new("cargo-foo", "1.0.0")
.file("src/main.rs", r#"
@ -786,6 +787,7 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
}
#[test]
#[ignore]
fn reports_unsuccessful_subcommand_result() {
Package::new("cargo-fail", "1.0.0")
.file("src/main.rs", r#"