nushell/crates/nu-cli/src/commands/version.rs

64 lines
1.4 KiB
Rust
Raw Normal View History

2019-08-19 03:30:29 +02:00
use crate::commands::WholeStreamCommand;
use crate::prelude::*;
use indexmap::IndexMap;
use nu_errors::ShellError;
2019-11-30 01:21:05 +01:00
use nu_protocol::{Dictionary, Signature, UntaggedValue};
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")
}
fn usage(&self) -> &str {
"Display Nu version"
}
2020-05-29 10:22:52 +02:00
async fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
version(args, registry)
}
2020-05-18 17:40:44 +02:00
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Display Nu version",
example: "version",
2020-05-18 17:40:44 +02:00
result: None,
}]
}
2019-08-19 03:30:29 +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
let mut indexmap = IndexMap::new();
indexmap.insert(
"version".to_string(),
UntaggedValue::string(clap::crate_version!()).into_value(&tag),
2019-08-19 03:30:29 +02:00
);
let value = UntaggedValue::Row(Dictionary::from(indexmap)).into_value(&tag);
2019-08-19 03:30:29 +02:00
Ok(OutputStream::one(value))
}
#[cfg(test)]
mod tests {
use super::Version;
#[test]
fn examples_work_as_expected() {
use crate::examples::test as test_examples;
test_examples(Version {})
}
}