forked from extern/nushell
Merge pull request #309 from twe4ked/version-command
Introduce version command
This commit is contained in:
commit
7b2b671b1e
@ -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