Skip to content

Commit 083576b

Browse files
committed
Implemented --compact flag for rust-lang#61.
1 parent 5e17913 commit 083576b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/bin/cargo_semver.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn main() {
7777
cli::exit_with_error(&config, e);
7878
}
7979

80-
if let Err(e) = run(&config, &matches, matches.opt_present("e")) {
80+
if let Err(e) = run(&config, &matches) {
8181
cli::exit_with_error(&config, e);
8282
}
8383
}
@@ -86,10 +86,13 @@ fn main() {
8686
/// "stable" version, compile them both into `rlib`s, and report the breaking
8787
/// introduced in the "current" version with respect to the "stable" version.
8888
// TODO: possibly reduce the complexity by finding where some info can be taken from directly
89-
fn run(config: &cargo::Config, matches: &getopts::Matches, explain: bool) -> Result<()> {
89+
fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
9090
use cargo::util::important_paths::find_root_manifest_for_wd;
9191
debug!("running cargo-semver");
9292

93+
let explain = matches.opt_present("e");
94+
let compact = matches.opt_present("compact");
95+
9396
// Obtain WorkInfo for the "current"
9497
let current = if let Some(name_and_version) = matches.opt_str("C") {
9598
// -C "name:version" requires fetching the appropriate package:
@@ -170,6 +173,7 @@ fn run(config: &cargo::Config, matches: &getopts::Matches, explain: bool) -> Res
170173
.stdin(Stdio::piped())
171174
.env("RUST_SEMVER_CRATE_VERSION", stable_version)
172175
.env("RUST_SEMVER_VERBOSE", format!("{}", explain))
176+
.env("RUST_SEMVER_COMPACT", format!("{}", compact))
173177
.env(
174178
"RUST_SEMVER_API_GUIDELINES",
175179
if matches.opt_present("a") {
@@ -237,6 +241,11 @@ mod cli {
237241
"no-default-features",
238242
"Do not activate the `default` feature",
239243
);
244+
opts.optflag(
245+
"",
246+
"compact",
247+
"Only output the suggested version on stdout for further processing",
248+
);
240249
opts.optopt(
241250
"s",
242251
"stable-path",

src/bin/rust_semverver.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ fn main() {
4646

4747
let verbose =
4848
std::env::var("RUST_SEMVER_VERBOSE") == Ok("true".to_string());
49+
let compact =
50+
std::env::var("RUST_SEMVER_COMPACT") == Ok("true".to_string());
4951
let api_guidelines =
5052
std::env::var("RUST_SEMVER_API_GUIDELINES") == Ok("true".to_string());
5153
let version = if let Ok(ver) = std::env::var("RUST_SEMVER_CRATE_VERSION") {
@@ -84,7 +86,7 @@ fn main() {
8486
if let [(_, old_def_id), (_, new_def_id)] = *crates.as_slice() {
8587
debug!("running semver analysis");
8688
let changes = run_analysis(tcx, old_def_id, new_def_id);
87-
changes.output(tcx.sess, &version, verbose, api_guidelines);
89+
changes.output(tcx.sess, &version, verbose, compact, api_guidelines);
8890
} else {
8991
tcx.sess.err("could not find crate old and new crates");
9092
}

src/changes.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,12 @@ impl<'tcx> ChangeSet<'tcx> {
879879
}
880880

881881
/// Format the contents of a change set for user output.
882-
pub fn output(&self, session: &Session, version: &str, verbose: bool, api_guidelines: bool) {
882+
pub fn output(&self,
883+
session: &Session,
884+
version: &str,
885+
verbose: bool,
886+
compact: bool,
887+
api_guidelines: bool) {
883888
if let Ok(mut new_version) = Version::parse(version) {
884889
if new_version.major == 0 {
885890
new_version.increment_patch();
@@ -891,10 +896,14 @@ impl<'tcx> ChangeSet<'tcx> {
891896
}
892897
}
893898

894-
println!(
895-
"version bump: {} -> ({}) -> {}",
896-
version, self.max, new_version
897-
);
899+
if compact {
900+
println!("{}", new_version);
901+
} else {
902+
println!(
903+
"version bump: {} -> ({}) -> {}",
904+
version, self.max, new_version
905+
);
906+
}
898907
} else {
899908
println!("max change: {}, could not parse {}", self.max, version);
900909
}

0 commit comments

Comments
 (0)