2019-08-19 03:30:29 +02:00
|
|
|
use crate::commands::WholeStreamCommand;
|
|
|
|
use crate::prelude::*;
|
|
|
|
use indexmap::IndexMap;
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
use nu_errors::ShellError;
|
2020-12-01 20:57:49 +01:00
|
|
|
use nu_protocol::{value::StrExt, value::StringExt, Dictionary, Signature, UntaggedValue};
|
2020-08-12 20:51:12 +02:00
|
|
|
|
2020-12-01 20:57:49 +01:00
|
|
|
pub mod shadow {
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
|
|
|
|
}
|
2019-08-19 03:30:29 +02:00
|
|
|
pub struct Version;
|
|
|
|
|
2020-05-29 10:22:52 +02:00
|
|
|
#[async_trait]
|
2019-08-19 03:30:29 +02:00
|
|
|
impl WholeStreamCommand for Version {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"version"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("version")
|
|
|
|
}
|
2019-08-30 00:52:32 +02:00
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
|
|
|
"Display Nu version"
|
|
|
|
}
|
|
|
|
|
2020-05-29 10:22:52 +02:00
|
|
|
async fn run(
|
2019-08-30 00:52:32 +02:00
|
|
|
&self,
|
|
|
|
args: CommandArgs,
|
|
|
|
registry: &CommandRegistry,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
2020-01-11 21:49:20 +01:00
|
|
|
version(args, registry)
|
2019-08-30 00:52:32 +02:00
|
|
|
}
|
2020-05-18 09:11:37 +02:00
|
|
|
|
2020-05-18 17:40:44 +02:00
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
|
|
vec![Example {
|
2020-05-18 09:11:37 +02:00
|
|
|
description: "Display Nu version",
|
|
|
|
example: "version",
|
2020-05-18 17:40:44 +02:00
|
|
|
result: None,
|
2020-05-18 09:11:37 +02:00
|
|
|
}]
|
|
|
|
}
|
2019-08-19 03:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 05:18:24 +02:00
|
|
|
pub fn version(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
|
|
|
let tag = args.call_info.args.span;
|
2019-08-19 03:30:29 +02:00
|
|
|
|
2020-08-12 05:13:33 +02:00
|
|
|
let mut indexmap = IndexMap::with_capacity(4);
|
2020-08-08 07:39:34 +02:00
|
|
|
|
2019-08-19 03:30:29 +02:00
|
|
|
indexmap.insert(
|
|
|
|
"version".to_string(),
|
2019-12-04 20:52:31 +01:00
|
|
|
UntaggedValue::string(clap::crate_version!()).into_value(&tag),
|
2019-08-19 03:30:29 +02:00
|
|
|
);
|
2020-08-11 23:43:23 +02:00
|
|
|
|
2020-12-01 20:57:49 +01:00
|
|
|
let branch: Option<&str> = Some(shadow::BRANCH).filter(|x| !x.is_empty());
|
|
|
|
if let Some(branch) = branch {
|
|
|
|
indexmap.insert(
|
|
|
|
"branch".to_string(),
|
|
|
|
branch.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let short_commit: Option<&str> = Some(shadow::SHORT_COMMIT).filter(|x| !x.is_empty());
|
|
|
|
if let Some(short_commit) = short_commit {
|
|
|
|
indexmap.insert(
|
|
|
|
"short_commit".to_string(),
|
|
|
|
short_commit.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
let commit_hash: Option<&str> = Some(shadow::COMMIT_HASH).filter(|x| !x.is_empty());
|
2020-08-12 20:51:12 +02:00
|
|
|
if let Some(commit_hash) = commit_hash {
|
|
|
|
indexmap.insert(
|
|
|
|
"commit_hash".to_string(),
|
2020-12-01 20:57:49 +01:00
|
|
|
commit_hash.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
let commit_date: Option<&str> = Some(shadow::COMMIT_DATE).filter(|x| !x.is_empty());
|
|
|
|
if let Some(commit_date) = commit_date {
|
|
|
|
indexmap.insert(
|
|
|
|
"commit_date".to_string(),
|
|
|
|
commit_date.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// let commit_author: Option<&str> = Some(shadow::COMMIT_AUTHOR).filter(|x| !x.is_empty());
|
|
|
|
// if let Some(commit_author) = commit_author {
|
|
|
|
// indexmap.insert(
|
|
|
|
// "commit_author".to_string(),
|
|
|
|
// commit_author.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
let _commit_autor = shadow::COMMIT_AUTHOR;
|
|
|
|
|
|
|
|
// let commit_email: Option<&str> = Some(shadow::COMMIT_EMAIL).filter(|x| !x.is_empty());
|
|
|
|
// if let Some(commit_email) = commit_email {
|
|
|
|
// indexmap.insert(
|
|
|
|
// "commit_email".to_string(),
|
|
|
|
// commit_email.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
let _commit_email = shadow::COMMIT_EMAIL;
|
|
|
|
|
|
|
|
let build_os: Option<&str> = Some(shadow::BUILD_OS).filter(|x| !x.is_empty());
|
|
|
|
if let Some(build_os) = build_os {
|
|
|
|
indexmap.insert(
|
|
|
|
"build_os".to_string(),
|
|
|
|
build_os.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let rust_version: Option<&str> = Some(shadow::RUST_VERSION).filter(|x| !x.is_empty());
|
|
|
|
if let Some(rust_version) = rust_version {
|
|
|
|
indexmap.insert(
|
|
|
|
"rust_version".to_string(),
|
|
|
|
rust_version.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let rust_channel: Option<&str> = Some(shadow::RUST_CHANNEL).filter(|x| !x.is_empty());
|
|
|
|
if let Some(rust_channel) = rust_channel {
|
|
|
|
indexmap.insert(
|
|
|
|
"rust_channel".to_string(),
|
|
|
|
rust_channel.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let cargo_version: Option<&str> = Some(shadow::CARGO_VERSION).filter(|x| !x.is_empty());
|
|
|
|
if let Some(cargo_version) = cargo_version {
|
|
|
|
indexmap.insert(
|
|
|
|
"cargo_version".to_string(),
|
|
|
|
cargo_version.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let pkg_version: Option<&str> = Some(shadow::PKG_VERSION).filter(|x| !x.is_empty());
|
|
|
|
if let Some(pkg_version) = pkg_version {
|
|
|
|
indexmap.insert(
|
|
|
|
"pkg_version".to_string(),
|
|
|
|
pkg_version.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// let cargo_tree: Option<&str> = Some(shadow::CARGO_TREE).filter(|x| !x.is_empty());
|
|
|
|
// if let Some(cargo_tree) = cargo_tree {
|
|
|
|
// indexmap.insert(
|
|
|
|
// "cargo_tree".to_string(),
|
|
|
|
// cargo_tree.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
let _cargo_tree = shadow::CARGO_TREE;
|
|
|
|
|
|
|
|
// let project_name: Option<&str> = Some(shadow::PROJECT_NAME).filter(|x| !x.is_empty());
|
|
|
|
// if let Some(project_name) = project_name {
|
|
|
|
// indexmap.insert(
|
|
|
|
// "project_name".to_string(),
|
|
|
|
// project_name.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
let _project_name = shadow::PROJECT_NAME;
|
|
|
|
|
|
|
|
let build_time: Option<&str> = Some(shadow::BUILD_TIME).filter(|x| !x.is_empty());
|
|
|
|
if let Some(build_time) = build_time {
|
|
|
|
indexmap.insert(
|
|
|
|
"build_time".to_string(),
|
|
|
|
build_time.to_pattern_untagged_value().into_value(&tag),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let build_rust_channel: Option<&str> =
|
|
|
|
Some(shadow::BUILD_RUST_CHANNEL).filter(|x| !x.is_empty());
|
|
|
|
if let Some(build_rust_channel) = build_rust_channel {
|
|
|
|
indexmap.insert(
|
|
|
|
"build_rust_channel".to_string(),
|
|
|
|
build_rust_channel
|
|
|
|
.to_pattern_untagged_value()
|
|
|
|
.into_value(&tag),
|
2020-08-12 20:51:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-01 20:57:49 +01:00
|
|
|
indexmap.insert(
|
|
|
|
"features".to_string(),
|
|
|
|
features_enabled().join(", ").to_string_value_create_tag(),
|
|
|
|
);
|
2019-08-19 03:30:29 +02:00
|
|
|
|
2019-11-21 15:33:14 +01:00
|
|
|
let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag);
|
2019-08-19 03:30:29 +02:00
|
|
|
Ok(OutputStream::one(value))
|
|
|
|
}
|
2020-05-18 14:56:01 +02:00
|
|
|
|
2020-12-01 20:57:49 +01:00
|
|
|
fn features_enabled() -> Vec<String> {
|
|
|
|
let mut names = vec![];
|
2020-08-12 05:13:33 +02:00
|
|
|
|
2020-12-01 20:57:49 +01:00
|
|
|
names.push("default".to_string());
|
|
|
|
|
|
|
|
#[cfg(feature = "ctrlc")]
|
|
|
|
{
|
|
|
|
names.push("ctrlc".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "dirs")]
|
|
|
|
{
|
|
|
|
names.push("dirs".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "directories")]
|
|
|
|
{
|
|
|
|
names.push("directories".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "git2")]
|
|
|
|
{
|
|
|
|
names.push("git".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "ptree")]
|
|
|
|
{
|
|
|
|
names.push("ptree".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "rich-benchmark")]
|
|
|
|
{
|
|
|
|
names.push("rich-benchmark".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "rustyline-support")]
|
|
|
|
{
|
|
|
|
names.push("rustyline".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "term")]
|
|
|
|
{
|
|
|
|
names.push("term".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "uuid_crate")]
|
|
|
|
{
|
|
|
|
names.push("uuid".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "which")]
|
|
|
|
{
|
|
|
|
names.push("which".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "ichwh")]
|
|
|
|
{
|
|
|
|
names.push("ichwh".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "zip")]
|
|
|
|
{
|
|
|
|
names.push("zip".to_string());
|
|
|
|
}
|
2020-08-12 05:13:33 +02:00
|
|
|
|
|
|
|
#[cfg(feature = "clipboard-cli")]
|
|
|
|
{
|
2020-12-01 20:57:49 +01:00
|
|
|
names.push("clipboard-cli".to_string());
|
2020-08-12 05:13:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "trash-support")]
|
|
|
|
{
|
2020-12-01 20:57:49 +01:00
|
|
|
names.push("trash".to_string());
|
2020-08-12 05:13:33 +02:00
|
|
|
}
|
|
|
|
|
2020-12-01 20:57:49 +01:00
|
|
|
// #[cfg(feature = "binaryview")]
|
|
|
|
// {
|
|
|
|
// names.push("binaryview".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "start")]
|
|
|
|
// {
|
|
|
|
// names.push("start".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "bson")]
|
|
|
|
// {
|
|
|
|
// names.push("bson".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "sqlite")]
|
|
|
|
// {
|
|
|
|
// names.push("sqlite".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "s3")]
|
|
|
|
// {
|
|
|
|
// names.push("s3".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "chart")]
|
|
|
|
// {
|
|
|
|
// names.push("chart".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "xpath")]
|
|
|
|
// {
|
|
|
|
// names.push("xpath".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "selector")]
|
|
|
|
// {
|
|
|
|
// names.push("selector".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "extra")]
|
|
|
|
// {
|
|
|
|
// names.push("extra".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "preserve_order")]
|
|
|
|
// {
|
|
|
|
// names.push("preserve_order".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "wee_alloc")]
|
|
|
|
// {
|
|
|
|
// names.push("wee_alloc".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #[cfg(feature = "console_error_panic_hook")]
|
|
|
|
// {
|
|
|
|
// names.push("console_error_panic_hook".to_string());
|
|
|
|
// }
|
|
|
|
|
|
|
|
names.sort();
|
|
|
|
|
2020-08-12 05:13:33 +02:00
|
|
|
names
|
|
|
|
}
|
|
|
|
|
2020-05-18 14:56:01 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-10-03 16:06:02 +02:00
|
|
|
use super::ShellError;
|
2020-05-18 14:56:01 +02:00
|
|
|
use super::Version;
|
|
|
|
|
|
|
|
#[test]
|
2020-10-03 16:06:02 +02:00
|
|
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
2020-05-18 14:56:01 +02:00
|
|
|
use crate::examples::test as test_examples;
|
|
|
|
|
2020-10-03 16:06:02 +02:00
|
|
|
Ok(test_examples(Version {})?)
|
2020-05-18 14:56:01 +02:00
|
|
|
}
|
|
|
|
}
|