From 5f48452e3b8da8dd76ddb9adf03e832a3041dac9 Mon Sep 17 00:00:00 2001 From: raccmonteiro <3062698+raccmonteiro@users.noreply.github.com> Date: Mon, 19 Dec 2022 12:40:57 +0000 Subject: [PATCH] some filesystem command signatures (#7464) # Description Signature for the following commands: - `cd` - `cp` - `glob` - `ls` - `mkdir` - `mv` - `open` - `rm` - `save` - `touch` Related to https://github.com/nushell/nushell/issues/7320 Co-authored-by: sholderbach --- crates/nu-command/src/filesystem/cd.rs | 1 + crates/nu-command/src/filesystem/cp.rs | 3 ++- crates/nu-command/src/filesystem/glob.rs | 3 ++- crates/nu-command/src/filesystem/ls.rs | 3 ++- crates/nu-command/src/filesystem/mkdir.rs | 3 ++- crates/nu-command/src/filesystem/mv.rs | 3 ++- crates/nu-command/src/filesystem/open.rs | 4 +++- crates/nu-command/src/filesystem/rm.rs | 10 ++++++++-- crates/nu-command/src/filesystem/save.rs | 4 +++- crates/nu-command/src/filesystem/touch.rs | 5 ++++- 10 files changed, 29 insertions(+), 10 deletions(-) diff --git a/crates/nu-command/src/filesystem/cd.rs b/crates/nu-command/src/filesystem/cd.rs index e96b281131..ef2c14f7e1 100644 --- a/crates/nu-command/src/filesystem/cd.rs +++ b/crates/nu-command/src/filesystem/cd.rs @@ -48,6 +48,7 @@ impl Command for Cd { fn signature(&self) -> nu_protocol::Signature { Signature::build("cd") + .input_output_types(vec![(Type::Nothing, Type::Nothing)]) .optional("path", SyntaxShape::Directory, "the path to change to") .input_output_types(vec![ (Type::Nothing, Type::Nothing), diff --git a/crates/nu-command/src/filesystem/cp.rs b/crates/nu-command/src/filesystem/cp.rs index b84d76a750..27a3b85c89 100644 --- a/crates/nu-command/src/filesystem/cp.rs +++ b/crates/nu-command/src/filesystem/cp.rs @@ -8,7 +8,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, - Spanned, SyntaxShape, Value, + Spanned, SyntaxShape, Type, Value, }; use super::util::try_interaction; @@ -40,6 +40,7 @@ impl Command for Cp { fn signature(&self) -> Signature { Signature::build("cp") + .input_output_types(vec![(Type::Nothing, Type::Nothing)]) .required("source", SyntaxShape::GlobPattern, "the place to copy from") .required("destination", SyntaxShape::Filepath, "the place to copy to") .switch( diff --git a/crates/nu-command/src/filesystem/glob.rs b/crates/nu-command/src/filesystem/glob.rs index c3003fe291..08dfbc7264 100644 --- a/crates/nu-command/src/filesystem/glob.rs +++ b/crates/nu-command/src/filesystem/glob.rs @@ -4,7 +4,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Spanned, - SyntaxShape, Value, + SyntaxShape, Type, Value, }; use wax::{Glob as WaxGlob, WalkBehavior}; @@ -18,6 +18,7 @@ impl Command for Glob { fn signature(&self) -> Signature { Signature::build("glob") + .input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))]) .required("glob", SyntaxShape::String, "the glob expression") .named( "depth", diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index d984af547d..948a944a21 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -9,7 +9,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ Category, DataSource, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, - PipelineMetadata, ShellError, Signature, Span, Spanned, SyntaxShape, Value, + PipelineMetadata, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, }; use pathdiff::diff_paths; @@ -37,6 +37,7 @@ impl Command for Ls { fn signature(&self) -> nu_protocol::Signature { Signature::build("ls") + .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) // Using a string instead of a glob pattern shape so it won't auto-expand .optional("pattern", SyntaxShape::String, "the glob pattern to use") .switch("all", "Show hidden files", Some('a')) diff --git a/crates/nu-command/src/filesystem/mkdir.rs b/crates/nu-command/src/filesystem/mkdir.rs index c3c732fa4c..07b7e199da 100644 --- a/crates/nu-command/src/filesystem/mkdir.rs +++ b/crates/nu-command/src/filesystem/mkdir.rs @@ -6,7 +6,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, - SyntaxShape, Value, + SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -19,6 +19,7 @@ impl Command for Mkdir { fn signature(&self) -> Signature { Signature::build("mkdir") + .input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))]) .rest( "rest", SyntaxShape::Directory, diff --git a/crates/nu-command/src/filesystem/mv.rs b/crates/nu-command/src/filesystem/mv.rs index 39770ba8df..1d621c4999 100644 --- a/crates/nu-command/src/filesystem/mv.rs +++ b/crates/nu-command/src/filesystem/mv.rs @@ -7,7 +7,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, - Spanned, SyntaxShape, Value, + Spanned, SyntaxShape, Type, Value, }; const GLOB_PARAMS: nu_glob::MatchOptions = nu_glob::MatchOptions { @@ -35,6 +35,7 @@ impl Command for Mv { fn signature(&self) -> nu_protocol::Signature { Signature::build("mv") + .input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))]) .required( "source", SyntaxShape::GlobPattern, diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 6d74d97147..74a49a168f 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -3,7 +3,8 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Value, + Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Type, + Value, }; use std::io::BufReader; @@ -35,6 +36,7 @@ impl Command for Open { fn signature(&self) -> nu_protocol::Signature { Signature::build("open") + .input_output_types(vec![(Type::Nothing, Type::Any), (Type::String, Type::Any)]) .optional("filename", SyntaxShape::Filepath, "the filename to use") .switch("raw", "open file as raw binary", Some('r')) .category(Category::FileSystem) diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index c3b336e709..d4ff0a761f 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -44,7 +44,13 @@ impl Command for Rm { } fn signature(&self) -> Signature { - let sig = Signature::build("rm"); + let sig = Signature::build("rm") + .input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))]) + .required( + "filename", + SyntaxShape::Filepath, + "the path of the file you want to remove", + ); #[cfg(all( feature = "trash-support", not(target_os = "android"), @@ -73,7 +79,7 @@ impl Command for Rm { .rest( "rest", SyntaxShape::GlobPattern, - "the file path(s) to remove", + "additional file path(s) to remove", ) .category(Category::FileSystem) } diff --git a/crates/nu-command/src/filesystem/save.rs b/crates/nu-command/src/filesystem/save.rs index f105e5e76d..c87a22966c 100644 --- a/crates/nu-command/src/filesystem/save.rs +++ b/crates/nu-command/src/filesystem/save.rs @@ -2,7 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Value, + Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Type, + Value, }; use std::fs::File; use std::io::{BufWriter, Write}; @@ -35,6 +36,7 @@ impl Command for Save { fn signature(&self) -> nu_protocol::Signature { Signature::build("save") + .input_output_types(vec![(Type::Any, Type::Nothing)]) .required("filename", SyntaxShape::Filepath, "the filename to use") .named( "stderr", diff --git a/crates/nu-command/src/filesystem/touch.rs b/crates/nu-command/src/filesystem/touch.rs index 1fd33dd04c..a107892290 100644 --- a/crates/nu-command/src/filesystem/touch.rs +++ b/crates/nu-command/src/filesystem/touch.rs @@ -7,7 +7,9 @@ use filetime::FileTime; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, +}; #[derive(Clone)] pub struct Touch; @@ -23,6 +25,7 @@ impl Command for Touch { fn signature(&self) -> Signature { Signature::build("touch") + .input_output_types(vec![ (Type::Nothing, Type::Nothing) ]) .required( "filename", SyntaxShape::Filepath,