Skip to content

Commit

Permalink
Support abbreviating --release as -r
Browse files Browse the repository at this point in the history
Of the options people regularly pass to cargo, `--release` seems by far
the most common. Yet even on the command line, we expect people to type
out `--release`.

Add a short version `-r`, and add some tests in the testsuite that
confirm it works.
  • Loading branch information
joshtriplett committed Nov 29, 2021
1 parent 8032ac5 commit 2f53ca2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub trait AppExt: Sized {
}

fn arg_release(self, release: &'static str) -> Self {
self._arg(opt("release", release))
self._arg(opt("release", release).short("r"))
}

fn arg_profile(self, profile: &'static str) -> Self {
Expand Down
19 changes: 19 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,25 @@ fn verbose_release_build() {
.run();
}

#[cargo_test]
fn verbose_release_build_short() {
let p = project().file("src/lib.rs", "").build();
p.cargo("build -v -r")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]\
-C opt-level=3[..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/release/deps`
[FINISHED] release [optimized] target(s) in [..]
",
)
.run();
}

#[cargo_test]
fn verbose_release_build_deps() {
let p = project()
Expand Down
23 changes: 23 additions & 0 deletions tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,29 @@ fn release_works() {
assert!(p.release_bin("foo").is_file());
}

#[cargo_test]
fn release_short_works() {
let p = project()
.file(
"src/main.rs",
r#"
fn main() { if cfg!(debug_assertions) { panic!() } }
"#,
)
.build();

p.cargo("run -r")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] `target/release/foo[EXE]`
",
)
.run();
assert!(p.release_bin("foo").is_file());
}

#[cargo_test]
fn run_bin_different_name() {
let p = project()
Expand Down

0 comments on commit 2f53ca2

Please sign in to comment.