From e372e7c44899a9bad21dfc216e101c9892822c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Tue, 11 Aug 2020 22:13:33 -0500 Subject: [PATCH] Display built features. Long/Short commit hashes display removed due to cargo publishing. (#2333) Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: Jonathan Turner Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: Jonathan Turner --- crates/nu-cli/Cargo.toml | 2 -- crates/nu-cli/src/commands/version.rs | 38 ++++++++++++++++++--------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index e509082fe9..657eea1acb 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -52,7 +52,6 @@ ical = "0.6.*" ichwh = {version = "0.3.4", optional = true} indexmap = {version = "1.4.0", features = ["serde-1"]} itertools = "0.9.0" -last-git-commit = "0.2.0" log = "0.4.8" meval = "0.2" natural = "0.5.0" @@ -115,7 +114,6 @@ optional = true version = "0.23.1" [build-dependencies] -git2 = "0.13" [dev-dependencies] quickcheck = "0.9" diff --git a/crates/nu-cli/src/commands/version.rs b/crates/nu-cli/src/commands/version.rs index cfd9fe9541..5ca2d2e13c 100644 --- a/crates/nu-cli/src/commands/version.rs +++ b/crates/nu-cli/src/commands/version.rs @@ -1,7 +1,7 @@ use crate::commands::WholeStreamCommand; use crate::prelude::*; +use crate::TaggedListBuilder; use indexmap::IndexMap; -use last_git_commit::LastGitCommit; use nu_errors::ShellError; use nu_protocol::{Dictionary, Signature, UntaggedValue}; @@ -41,28 +41,42 @@ impl WholeStreamCommand for Version { pub fn version(args: CommandArgs, _registry: &CommandRegistry) -> Result { let tag = args.call_info.args.span; - let mut indexmap = IndexMap::with_capacity(3); + let mut indexmap = IndexMap::with_capacity(4); indexmap.insert( "version".to_string(), UntaggedValue::string(clap::crate_version!()).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), - ); - } + indexmap.insert("features".to_string(), features_enabled(&tag).into_value()); let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag); Ok(OutputStream::one(value)) } +fn features_enabled(tag: impl Into) -> TaggedListBuilder { + let mut names = TaggedListBuilder::new(tag); + + names.push_untagged(UntaggedValue::string("default")); + + #[cfg(feature = "clipboard-cli")] + { + names.push_untagged(UntaggedValue::string("clipboard")); + } + + #[cfg(feature = "trash-support")] + { + names.push_untagged(UntaggedValue::string("trash")); + } + + #[cfg(feature = "starship-prompt")] + { + names.push_untagged(UntaggedValue::string("starship")); + } + + names +} + #[cfg(test)] mod tests { use super::Version;