mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 15:39:06 +01:00
Introduce version command
This commit is contained in:
parent
81d83d7655
commit
4de6c941e1
@ -194,6 +194,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
|||||||
whole_stream_command(Save),
|
whole_stream_command(Save),
|
||||||
whole_stream_command(Table),
|
whole_stream_command(Table),
|
||||||
whole_stream_command(VTable),
|
whole_stream_command(VTable),
|
||||||
|
whole_stream_command(Version),
|
||||||
whole_stream_command(Which),
|
whole_stream_command(Which),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ crate mod to_json;
|
|||||||
crate mod to_toml;
|
crate mod to_toml;
|
||||||
crate mod to_yaml;
|
crate mod to_yaml;
|
||||||
crate mod trim;
|
crate mod trim;
|
||||||
|
crate mod version;
|
||||||
crate mod vtable;
|
crate mod vtable;
|
||||||
crate mod where_;
|
crate mod where_;
|
||||||
crate mod which_;
|
crate mod which_;
|
||||||
@ -74,6 +75,7 @@ crate use rm::Remove;
|
|||||||
crate use save::Save;
|
crate use save::Save;
|
||||||
crate use skip_while::SkipWhile;
|
crate use skip_while::SkipWhile;
|
||||||
crate use table::Table;
|
crate use table::Table;
|
||||||
|
crate use version::Version;
|
||||||
crate use vtable::VTable;
|
crate use vtable::VTable;
|
||||||
crate use where_::Where;
|
crate use where_::Where;
|
||||||
crate use which_::Which;
|
crate use which_::Which;
|
||||||
|
42
src/commands/version.rs
Normal file
42
src/commands/version.rs
Normal file
@ -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<OutputStream, ShellError> {
|
||||||
|
date(args, registry)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"version"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("version")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||||
|
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))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user