Updated version hashing and bumped nu-cli to 0.18.1 (#2331)

* Updated version hashing and bumped nu-cli to 0.18.1

* made code pertyer

* Update version.rs

* Update version.rs

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
This commit is contained in:
Darren Schroeder
2020-08-11 16:43:23 -05:00
committed by GitHub
parent cc3c10867c
commit 0194dee3a6
6 changed files with 28 additions and 52 deletions

View File

@ -1,11 +1,10 @@
use crate::commands::WholeStreamCommand;
use crate::prelude::*;
use indexmap::IndexMap;
use last_git_commit::LastGitCommit;
use nu_errors::ShellError;
use nu_protocol::{Dictionary, Signature, UntaggedValue};
const GIT_COMMIT_HASH: &str = include_str!(concat!(env!("OUT_DIR"), "/git_commit_hash"));
pub struct Version;
#[async_trait]
@ -42,16 +41,23 @@ impl WholeStreamCommand for Version {
pub fn version(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let tag = args.call_info.args.span;
let mut indexmap = IndexMap::with_capacity(2);
let mut indexmap = IndexMap::with_capacity(3);
indexmap.insert(
"version".to_string(),
UntaggedValue::string(clap::crate_version!()).into_value(&tag),
);
indexmap.insert(
"commit_hash".to_string(),
UntaggedValue::string(GIT_COMMIT_HASH).into_value(&tag),
);
if let Ok(lgc) = LastGitCommit::new().build() {
indexmap.insert(
"short_commit_hash".to_string(),
UntaggedValue::string(lgc.id().short()).into_value(&tag),
);
indexmap.insert(
"long_commit_hash".to_string(),
UntaggedValue::string(lgc.id().long()).into_value(&tag),
);
}
let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag);
Ok(OutputStream::one(value))