Skip to content

Commit 2f53ca2

Browse files
committed
Support abbreviating --release as -r
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.
1 parent 8032ac5 commit 2f53ca2

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/cargo/util/command_prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub trait AppExt: Sized {
142142
}
143143

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

148148
fn arg_profile(self, profile: &'static str) -> Self {

tests/testsuite/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,25 @@ fn verbose_release_build() {
17751775
.run();
17761776
}
17771777

1778+
#[cargo_test]
1779+
fn verbose_release_build_short() {
1780+
let p = project().file("src/lib.rs", "").build();
1781+
p.cargo("build -v -r")
1782+
.with_stderr(
1783+
"\
1784+
[COMPILING] foo v0.0.1 ([CWD])
1785+
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1786+
--emit=[..]link[..]\
1787+
-C opt-level=3[..]\
1788+
-C metadata=[..] \
1789+
--out-dir [..] \
1790+
-L dependency=[CWD]/target/release/deps`
1791+
[FINISHED] release [optimized] target(s) in [..]
1792+
",
1793+
)
1794+
.run();
1795+
}
1796+
17781797
#[cargo_test]
17791798
fn verbose_release_build_deps() {
17801799
let p = project()

tests/testsuite/run.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,29 @@ fn release_works() {
936936
assert!(p.release_bin("foo").is_file());
937937
}
938938

939+
#[cargo_test]
940+
fn release_short_works() {
941+
let p = project()
942+
.file(
943+
"src/main.rs",
944+
r#"
945+
fn main() { if cfg!(debug_assertions) { panic!() } }
946+
"#,
947+
)
948+
.build();
949+
950+
p.cargo("run -r")
951+
.with_stderr(
952+
"\
953+
[COMPILING] foo v0.0.1 ([CWD])
954+
[FINISHED] release [optimized] target(s) in [..]
955+
[RUNNING] `target/release/foo[EXE]`
956+
",
957+
)
958+
.run();
959+
assert!(p.release_bin("foo").is_file());
960+
}
961+
939962
#[cargo_test]
940963
fn run_bin_different_name() {
941964
let p = project()

0 commit comments

Comments
 (0)