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 <sholderbach@users.noreply.github.com>
This commit is contained in:
raccmonteiro 2022-12-19 12:40:57 +00:00 committed by GitHub
parent dae1b9a996
commit 5f48452e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 29 additions and 10 deletions

View File

@ -48,6 +48,7 @@ impl Command for Cd {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("cd") Signature::build("cd")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.optional("path", SyntaxShape::Directory, "the path to change to") .optional("path", SyntaxShape::Directory, "the path to change to")
.input_output_types(vec![ .input_output_types(vec![
(Type::Nothing, Type::Nothing), (Type::Nothing, Type::Nothing),

View File

@ -8,7 +8,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span,
Spanned, SyntaxShape, Value, Spanned, SyntaxShape, Type, Value,
}; };
use super::util::try_interaction; use super::util::try_interaction;
@ -40,6 +40,7 @@ impl Command for Cp {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("cp") Signature::build("cp")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.required("source", SyntaxShape::GlobPattern, "the place to copy from") .required("source", SyntaxShape::GlobPattern, "the place to copy from")
.required("destination", SyntaxShape::Filepath, "the place to copy to") .required("destination", SyntaxShape::Filepath, "the place to copy to")
.switch( .switch(

View File

@ -4,7 +4,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Spanned, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Spanned,
SyntaxShape, Value, SyntaxShape, Type, Value,
}; };
use wax::{Glob as WaxGlob, WalkBehavior}; use wax::{Glob as WaxGlob, WalkBehavior};
@ -18,6 +18,7 @@ impl Command for Glob {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("glob") Signature::build("glob")
.input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))])
.required("glob", SyntaxShape::String, "the glob expression") .required("glob", SyntaxShape::String, "the glob expression")
.named( .named(
"depth", "depth",

View File

@ -9,7 +9,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, DataSource, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, 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; use pathdiff::diff_paths;
@ -37,6 +37,7 @@ impl Command for Ls {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("ls") 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 // Using a string instead of a glob pattern shape so it won't auto-expand
.optional("pattern", SyntaxShape::String, "the glob pattern to use") .optional("pattern", SyntaxShape::String, "the glob pattern to use")
.switch("all", "Show hidden files", Some('a')) .switch("all", "Show hidden files", Some('a'))

View File

@ -6,7 +6,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature,
SyntaxShape, Value, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -19,6 +19,7 @@ impl Command for Mkdir {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("mkdir") Signature::build("mkdir")
.input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))])
.rest( .rest(
"rest", "rest",
SyntaxShape::Directory, SyntaxShape::Directory,

View File

@ -7,7 +7,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span,
Spanned, SyntaxShape, Value, Spanned, SyntaxShape, Type, Value,
}; };
const GLOB_PARAMS: nu_glob::MatchOptions = nu_glob::MatchOptions { const GLOB_PARAMS: nu_glob::MatchOptions = nu_glob::MatchOptions {
@ -35,6 +35,7 @@ impl Command for Mv {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("mv") Signature::build("mv")
.input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))])
.required( .required(
"source", "source",
SyntaxShape::GlobPattern, SyntaxShape::GlobPattern,

View File

@ -3,7 +3,8 @@ use nu_engine::{eval_block, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ 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; use std::io::BufReader;
@ -35,6 +36,7 @@ impl Command for Open {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("open") Signature::build("open")
.input_output_types(vec![(Type::Nothing, Type::Any), (Type::String, Type::Any)])
.optional("filename", SyntaxShape::Filepath, "the filename to use") .optional("filename", SyntaxShape::Filepath, "the filename to use")
.switch("raw", "open file as raw binary", Some('r')) .switch("raw", "open file as raw binary", Some('r'))
.category(Category::FileSystem) .category(Category::FileSystem)

View File

@ -44,7 +44,13 @@ impl Command for Rm {
} }
fn signature(&self) -> Signature { 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( #[cfg(all(
feature = "trash-support", feature = "trash-support",
not(target_os = "android"), not(target_os = "android"),
@ -73,7 +79,7 @@ impl Command for Rm {
.rest( .rest(
"rest", "rest",
SyntaxShape::GlobPattern, SyntaxShape::GlobPattern,
"the file path(s) to remove", "additional file path(s) to remove",
) )
.category(Category::FileSystem) .category(Category::FileSystem)
} }

View File

@ -2,7 +2,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ 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::fs::File;
use std::io::{BufWriter, Write}; use std::io::{BufWriter, Write};
@ -35,6 +36,7 @@ impl Command for Save {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("save") Signature::build("save")
.input_output_types(vec![(Type::Any, Type::Nothing)])
.required("filename", SyntaxShape::Filepath, "the filename to use") .required("filename", SyntaxShape::Filepath, "the filename to use")
.named( .named(
"stderr", "stderr",

View File

@ -7,7 +7,9 @@ use filetime::FileTime;
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; 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)] #[derive(Clone)]
pub struct Touch; pub struct Touch;
@ -23,6 +25,7 @@ impl Command for Touch {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("touch") Signature::build("touch")
.input_output_types(vec![ (Type::Nothing, Type::Nothing) ])
.required( .required(
"filename", "filename",
SyntaxShape::Filepath, SyntaxShape::Filepath,