Support version option in Nu bin. (#3632)

Additionally we remove the little pieces that we relied on `clap` (for version number in this case).
This commit is contained in:
Andrés N. Robalino
2021-06-16 14:53:28 -05:00
committed by GitHub
parent 18be6768c9
commit 2a946af81e
13 changed files with 129 additions and 56 deletions

View File

@ -35,7 +35,6 @@ bytes = "1.0.1"
calamine = "0.17.0"
chrono = { version = "0.4.19", features = ["serde"] }
chrono-tz = "0.5.3"
clap = "2.33.3"
codespan-reporting = "0.11.0"
crossterm = { version = "0.19.0", optional = true }
csv = "1.1.3"

View File

@ -134,7 +134,7 @@ pub(crate) mod to_yaml;
pub(crate) mod uniq;
pub(crate) mod update;
pub(crate) mod url_;
pub(crate) mod version;
pub mod version;
pub(crate) mod where_;
pub(crate) mod which_;
pub(crate) mod with_env;
@ -254,7 +254,7 @@ pub(crate) use path::{
PathBasename, PathCommand, PathDirname, PathExists, PathExpand, PathJoin, PathParse,
PathRelativeTo, PathSplit, PathType,
};
pub(crate) use pivot::Pivot;
pub use pivot::Pivot;
pub(crate) use prepend::Prepend;
pub(crate) use prev::Previous;
pub(crate) use pwd::Pwd;
@ -291,7 +291,7 @@ pub(crate) use str_::{
StrReverse, StrScreamingSnakeCase, StrSnakeCase, StrStartsWith, StrSubstring, StrToDatetime,
StrToDecimal, StrToInteger, StrTrim, StrTrimLeft, StrTrimRight, StrUpcase,
};
pub(crate) use table::Table;
pub use table::Table;
pub(crate) use tags::Tags;
pub(crate) use termsize::TermSize;
pub(crate) use to::To;
@ -307,7 +307,7 @@ pub(crate) use to_yaml::ToYaml;
pub(crate) use touch::Touch;
pub(crate) use uniq::Uniq;
pub(crate) use url_::{UrlCommand, UrlHost, UrlPath, UrlQuery, UrlScheme};
pub(crate) use version::Version;
pub use version::Version;
pub(crate) use where_::Command as Where;
pub(crate) use which_::Which;
pub(crate) use with_env::WithEnv;

View File

@ -10,6 +10,7 @@ impl WholeStreamCommand for Command {
fn signature(&self) -> Signature {
Signature::build("nu")
.switch("version", "Display Nu version", Some('v'))
.switch("stdin", "redirect stdin", None)
.switch("skip-plugins", "do not load plugins", None)
.switch("no-history", "don't save history", None)
@ -46,19 +47,3 @@ impl WholeStreamCommand for Command {
"Nu - A new type of shell."
}
}
pub fn testbins() -> Vec<String> {
vec![
"echo_env", "cococo", "iecho", "fail", "nonu", "chop", "repeater", "meow",
]
.into_iter()
.map(String::from)
.collect()
}
pub fn loglevels() -> Vec<String> {
vec!["error", "warn", "info", "debug", "trace"]
.into_iter()
.map(String::from)
.collect()
}

View File

@ -2,5 +2,24 @@ pub mod command;
mod plugin;
pub use command::Command as Nu;
pub use command::{loglevels, testbins};
pub use plugin::SubCommand as NuPlugin;
pub fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
pub fn testbins() -> Vec<String> {
vec![
"echo_env", "cococo", "iecho", "fail", "nonu", "chop", "repeater", "meow",
]
.into_iter()
.map(String::from)
.collect()
}
pub fn loglevels() -> Vec<String> {
vec!["error", "warn", "info", "debug", "trace"]
.into_iter()
.map(String::from)
.collect()
}

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for Version {
"Display Nu version."
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
version(args)
}
@ -36,14 +36,14 @@ impl WholeStreamCommand for Version {
}
}
pub fn version(args: CommandArgs) -> Result<ActionStream, ShellError> {
pub fn version(args: CommandArgs) -> Result<OutputStream, ShellError> {
let tag = args.call_info.args.span;
let mut indexmap = IndexMap::with_capacity(4);
indexmap.insert(
"version".to_string(),
UntaggedValue::string(clap::crate_version!()).into_value(&tag),
UntaggedValue::string(super::nu::version()).into_value(&tag),
);
let branch: Option<&str> = Some(shadow::BRANCH).filter(|x| !x.is_empty());
@ -178,7 +178,7 @@ pub fn version(args: CommandArgs) -> Result<ActionStream, ShellError> {
);
let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag);
Ok(ActionStream::one(value))
Ok(OutputStream::one(value))
}
fn features_enabled() -> Vec<String> {