mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 15:39:06 +01:00
Merge pull request #612 from chhetripradeep/pchhetri/add-pwd-command
Adds pwd command
This commit is contained in:
commit
90b358d60b
@ -164,6 +164,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
context.add_commands(vec![
|
context.add_commands(vec![
|
||||||
whole_stream_command(PS),
|
whole_stream_command(PS),
|
||||||
|
whole_stream_command(PWD),
|
||||||
whole_stream_command(LS),
|
whole_stream_command(LS),
|
||||||
whole_stream_command(CD),
|
whole_stream_command(CD),
|
||||||
whole_stream_command(Size),
|
whole_stream_command(Size),
|
||||||
|
@ -39,6 +39,7 @@ pub(crate) mod plugin;
|
|||||||
pub(crate) mod post;
|
pub(crate) mod post;
|
||||||
pub(crate) mod prev;
|
pub(crate) mod prev;
|
||||||
pub(crate) mod ps;
|
pub(crate) mod ps;
|
||||||
|
pub(crate) mod pwd;
|
||||||
pub(crate) mod reject;
|
pub(crate) mod reject;
|
||||||
pub(crate) mod reverse;
|
pub(crate) mod reverse;
|
||||||
pub(crate) mod rm;
|
pub(crate) mod rm;
|
||||||
@ -104,6 +105,7 @@ pub(crate) use pick::Pick;
|
|||||||
pub(crate) use post::Post;
|
pub(crate) use post::Post;
|
||||||
pub(crate) use prev::Previous;
|
pub(crate) use prev::Previous;
|
||||||
pub(crate) use ps::PS;
|
pub(crate) use ps::PS;
|
||||||
|
pub(crate) use pwd::PWD;
|
||||||
pub(crate) use reject::Reject;
|
pub(crate) use reject::Reject;
|
||||||
pub(crate) use reverse::Reverse;
|
pub(crate) use reverse::Reverse;
|
||||||
pub(crate) use rm::Remove;
|
pub(crate) use rm::Remove;
|
||||||
|
44
src/commands/pwd.rs
Normal file
44
src/commands/pwd.rs
Normal 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))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user