Add commit hash to version command (#2312)

* Add commit to version command

* Replace unwrap with expect.
This commit is contained in:
Shaurya Shubham
2020-08-08 11:09:34 +05:30
committed by GitHub
parent 724b177c97
commit 362bb1bea3
4 changed files with 69 additions and 1 deletions

View File

@ -4,6 +4,8 @@ use indexmap::IndexMap;
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]
@ -40,11 +42,16 @@ 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::new();
let mut indexmap = IndexMap::with_capacity(2);
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),
);
let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag);
Ok(OutputStream::one(value))