Skip to content

Commit

Permalink
Auto merge of #6076 - matthiaskrgr:version_verbose, r=dwijnand
Browse files Browse the repository at this point in the history
cargo version: support --verbose

make obtaining of the version output an own function and use it in the "version" subcommand

makes "cargo version -v" work equivalent to "cargo -Vv"
  • Loading branch information
bors committed Sep 23, 2018
2 parents fd77d9d + 93095a8 commit 9b5b295
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
35 changes: 21 additions & 14 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,8 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"

let is_verbose = args.occurrences_of("verbose") > 0;
if args.is_present("version") {
let version = cargo::version();
println!("{}", version);
if is_verbose {
println!(
"release: {}.{}.{}",
version.major, version.minor, version.patch
);
if let Some(ref cfg) = version.cfg_info {
if let Some(ref ci) = cfg.commit_info {
println!("commit-hash: {}", ci.commit_hash);
println!("commit-date: {}", ci.commit_date);
}
}
}
let version = get_version_string(is_verbose);
print!("{}", version);
return Ok(());
}

Expand Down Expand Up @@ -91,6 +79,25 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
execute_subcommand(config, &args)
}

pub fn get_version_string(is_verbose: bool) -> String {
let version = cargo::version();
let mut version_string = String::from(version.to_string());
version_string.push_str("\n");
if is_verbose {
version_string.push_str(&format!(
"release: {}.{}.{}\n",
version.major, version.minor, version.patch
));
if let Some(ref cfg) = version.cfg_info {
if let Some(ref ci) = cfg.commit_info {
version_string.push_str(&format!("commit-hash: {}\n", ci.commit_hash));
version_string.push_str(&format!("commit-date: {}\n", ci.commit_date));
}
}
}
version_string
}

fn expand_aliases(
config: &mut Config,
args: ArgMatches<'static>,
Expand Down
8 changes: 5 additions & 3 deletions src/bin/cargo/commands/version.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use command_prelude::*;

use cargo;
use cli;

pub fn cli() -> App {
subcommand("version").about("Show version information")
}

pub fn exec(_config: &mut Config, _args: &ArgMatches) -> CliResult {
println!("{}", cargo::version());
pub fn exec(_config: &mut Config, args: &ArgMatches) -> CliResult {
let verbose = args.occurrences_of("verbose") > 0;
let version = cli::get_version_string(verbose);
print!("{}", version);
Ok(())
}

0 comments on commit 9b5b295

Please sign in to comment.