Adds pwd command

This commit is contained in:
Pradeep Chhetri 2019-09-07 23:49:15 +08:00
parent 452f96a836
commit ee301f9f54
3 changed files with 47 additions and 0 deletions

View File

@ -164,6 +164,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
context.add_commands(vec![
whole_stream_command(PS),
whole_stream_command(PWD),
whole_stream_command(LS),
whole_stream_command(CD),
whole_stream_command(Size),

View File

@ -39,6 +39,7 @@ pub(crate) mod plugin;
pub(crate) mod post;
pub(crate) mod prev;
pub(crate) mod ps;
pub(crate) mod pwd;
pub(crate) mod reject;
pub(crate) mod reverse;
pub(crate) mod rm;
@ -104,6 +105,7 @@ pub(crate) use pick::Pick;
pub(crate) use post::Post;
pub(crate) use prev::Previous;
pub(crate) use ps::PS;
pub(crate) use pwd::PWD;
pub(crate) use reject::Reject;
pub(crate) use reverse::Reverse;
pub(crate) use rm::Remove;

44
src/commands/pwd.rs Normal file
View File

@ -0,0 +1,44 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{Dictionary, Value};
use crate::parser::registry::Signature;
use crate::prelude::*;
use indexmap::IndexMap;
pub struct PWD;
impl WholeStreamCommand for PWD {
fn name(&self) -> &str {
"pwd"
}
fn signature(&self) -> Signature {
Signature::build("pwd")
}
fn usage(&self) -> &str {
"Output the current working directory."
}
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
pwd(args, registry)
}
}
pub fn pwd(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(
"name".to_string(),
Tagged::from_simple_spanned_item(Value::string(std::env::current_dir()?.to_string_lossy()), span),
);
let value = Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span);
Ok(OutputStream::one(value))
}