diff --git a/src/cli.rs b/src/cli.rs index 8db08c8e67..02cd99e071 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -194,6 +194,7 @@ pub async fn cli() -> Result<(), Box> { whole_stream_command(Save), whole_stream_command(Table), whole_stream_command(VTable), + whole_stream_command(Version), whole_stream_command(Which), ]); } diff --git a/src/commands.rs b/src/commands.rs index 54f923607c..26dfb4fc35 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -50,6 +50,7 @@ crate mod to_json; crate mod to_toml; crate mod to_yaml; crate mod trim; +crate mod version; crate mod vtable; crate mod where_; crate mod which_; @@ -74,6 +75,7 @@ crate use rm::Remove; crate use save::Save; crate use skip_while::SkipWhile; crate use table::Table; +crate use version::Version; crate use vtable::VTable; crate use where_::Where; crate use which_::Which; diff --git a/src/commands/version.rs b/src/commands/version.rs new file mode 100644 index 0000000000..06653ae207 --- /dev/null +++ b/src/commands/version.rs @@ -0,0 +1,42 @@ +use crate::commands::WholeStreamCommand; +use crate::errors::ShellError; +use crate::object::{Dictionary, Value}; +use crate::parser::registry::Signature; +use crate::prelude::*; +use indexmap::IndexMap; + +const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + +pub struct Version; + +impl WholeStreamCommand for Version { + fn run( + &self, + args: CommandArgs, + registry: &CommandRegistry, + ) -> Result { + date(args, registry) + } + + fn name(&self) -> &str { + "version" + } + + fn signature(&self) -> Signature { + Signature::build("version") + } +} + +pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result { + let args = args.evaluate_once(registry)?; + let span = args.call_info.name_span; + + let mut indexmap = IndexMap::new(); + indexmap.insert( + "version".to_string(), + Tagged::from_simple_spanned_item(Value::string(VERSION.to_string()), span), + ); + + let value = Tagged::from_simple_spanned_item(Value::Object(Dictionary::from(indexmap)), span); + Ok(OutputStream::one(value)) +}