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

cargo version: support --verbose #6076

Merged
merged 1 commit into from
Sep 23, 2018
Merged
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
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(())
}