Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: switch to clap #5129

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ tempdir = "0.3"
termcolor = "0.3"
toml = "0.4"
url = "1.1"
clap = "2.27.0"

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = { version = "0.5.1", features = ["mac_os_10_7_support"] }
Expand Down
36 changes: 24 additions & 12 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern crate log;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate clap;

use std::collections::BTreeSet;
use std::collections::HashMap;
Expand All @@ -20,6 +21,8 @@ use cargo::core::shell::{Shell, Verbosity};
use cargo::util::{self, CliResult, lev_distance, Config, CargoResult};
use cargo::util::{CliError, ProcessError};

mod cli;

#[derive(Deserialize)]
pub struct Flags {
flag_list: bool,
Expand Down Expand Up @@ -85,17 +88,26 @@ fn main() {
}
};

let result = (|| {
let args: Vec<_> = try!(env::args_os()
.map(|s| {
s.into_string().map_err(|s| {
format_err!("invalid unicode in argument: {:?}", s)
let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() {
"build" | "bench" => 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)
})();
.collect());
let rest = &args;
cargo::call_main_without_stdin(execute, &mut config, USAGE, rest, true)
})()
};

match result {
Err(e) => cargo::exit_with_error(e, &mut *config.shell()),
Expand All @@ -105,8 +117,8 @@ fn main() {

macro_rules! each_subcommand{
($mac:ident) => {
$mac!(bench);
$mac!(build);
// $mac!(bench);
// $mac!(build);
$mac!(check);
$mac!(clean);
$mac!(doc);
Expand Down
66 changes: 66 additions & 0 deletions src/bin/cli/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use super::utils::*;

pub fn cli() -> App {
subcommand("bench")
.about("Execute all benchmarks of a local package")
.arg(
Arg::with_name("BENCHNAME").help(
"If specified, only run benches containing this string in their names"
)
)
.arg(
Arg::with_name("args").help(
"Arguments for the bench binary"
).multiple(true).last(true)
)

.arg_target(
"Benchmark only this package's library",
"Benchmark only the specified binary",
"Benchmark all binaries",
"Benchmark only the specified example",
"Benchmark all examples",
"Benchmark only the specified test target",
"Benchmark all tests",
"Benchmark only the specified bench target",
"Benchmark all benches",
"Benchmark all targets (default)",
)

.arg(
opt("no-run", "Compile, but don't run benchmarks")
)
.arg_package(
"Package to run benchmarks for",
"Benchmark all packages in the workspace",
"Exclude packages from the benchmark",
)
.arg_jobs()
.arg_features()
.arg_target_triple()
.arg_manifest_path()
.arg_message_format()
.arg(
opt("no-fail-fast", "Run all benchmarks regardless of failure")
)
.arg_locked()
.after_help("\
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.
")
}
47 changes: 47 additions & 0 deletions src/bin/cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use super::utils::*;

pub fn cli() -> App {
subcommand("build")
.about("Compile a local package and all of its dependencies")
.arg_package(
"Package to build",
"Build all packages in the workspace",
"Exclude packages from the build",
)
.arg_jobs()
.arg_target(
"Build only this package's library",
"Build only the specified binary",
"Build all binaries",
"Build only the specified example",
"Build all examples",
"Build only the specified test target",
"Build all tests",
"Build only the specified bench target",
"Build all benches",
"Build all targets (lib and bin targets by default)",
)
.arg(
opt("release", "Build artifacts in release mode, with optimizations")
)
.arg_features()
.arg_target_triple()
.arg_manifest_path()
.arg_message_format()
.arg_locked()
.after_help("\
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.
")

}
Loading