From b35914bd1754c61d3a4db70188eb52030301afff Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Wed, 17 Nov 2021 04:22:37 +0000 Subject: [PATCH] Category option for signature (#343) * category option for signature * category option for signature * column description for $scope --- .../nu-command/src/conversions/into/binary.rs | 14 ++-- .../src/conversions/into/command.rs | 4 +- .../src/conversions/into/filesize.rs | 14 ++-- crates/nu-command/src/conversions/into/int.rs | 14 ++-- .../nu-command/src/conversions/into/string.rs | 3 +- crates/nu-command/src/core_commands/alias.rs | 3 +- crates/nu-command/src/core_commands/def.rs | 3 +- crates/nu-command/src/core_commands/do_.rs | 3 +- crates/nu-command/src/core_commands/echo.rs | 8 ++- crates/nu-command/src/core_commands/export.rs | 4 +- .../src/core_commands/export_def.rs | 3 +- .../src/core_commands/export_env.rs | 3 +- crates/nu-command/src/core_commands/for_.rs | 4 +- crates/nu-command/src/core_commands/help.rs | 17 ++++- crates/nu-command/src/core_commands/hide.rs | 12 ++-- crates/nu-command/src/core_commands/if_.rs | 5 +- crates/nu-command/src/core_commands/let_.rs | 3 +- crates/nu-command/src/core_commands/module.rs | 3 +- .../nu-command/src/core_commands/register.rs | 14 ++-- crates/nu-command/src/core_commands/source.rs | 14 ++-- crates/nu-command/src/core_commands/use_.rs | 6 +- crates/nu-command/src/date/command.rs | 4 +- crates/nu-command/src/date/format.rs | 14 ++-- crates/nu-command/src/date/humanize.rs | 4 +- crates/nu-command/src/date/list_timezone.rs | 4 +- crates/nu-command/src/date/now.rs | 4 +- crates/nu-command/src/date/to_table.rs | 4 +- crates/nu-command/src/date/to_timezone.rs | 10 ++- crates/nu-command/src/env/let_env.rs | 3 +- crates/nu-command/src/env/with_env.rs | 3 +- crates/nu-command/src/experimental/git.rs | 4 +- .../src/experimental/git_checkout.rs | 14 ++-- .../src/experimental/list_git_branches.rs | 3 +- crates/nu-command/src/filesystem/cd.rs | 6 +- crates/nu-command/src/filesystem/cp.rs | 3 +- crates/nu-command/src/filesystem/ls.rs | 16 +++-- crates/nu-command/src/filesystem/mkdir.rs | 4 +- crates/nu-command/src/filesystem/mv.rs | 3 +- crates/nu-command/src/filesystem/rm.rs | 4 +- crates/nu-command/src/filesystem/touch.rs | 3 +- crates/nu-command/src/filters/collect.rs | 14 ++-- crates/nu-command/src/filters/each.rs | 5 +- crates/nu-command/src/filters/first.rs | 15 +++-- crates/nu-command/src/filters/get.rs | 14 ++-- crates/nu-command/src/filters/last.rs | 16 +++-- crates/nu-command/src/filters/length.rs | 4 +- crates/nu-command/src/filters/lines.rs | 6 +- crates/nu-command/src/filters/par_each.rs | 5 +- crates/nu-command/src/filters/range.rs | 16 +++-- crates/nu-command/src/filters/reverse.rs | 5 +- crates/nu-command/src/filters/select.rs | 16 +++-- crates/nu-command/src/filters/shuffle.rs | 4 +- crates/nu-command/src/filters/update.rs | 4 +- crates/nu-command/src/filters/where_.rs | 6 +- crates/nu-command/src/filters/wrap.rs | 7 +- crates/nu-command/src/filters/zip.rs | 8 ++- crates/nu-command/src/formats/from/command.rs | 4 +- crates/nu-command/src/formats/from/csv.rs | 3 +- crates/nu-command/src/formats/from/eml.rs | 15 +++-- crates/nu-command/src/formats/from/json.rs | 12 ++-- crates/nu-command/src/formats/from/tsv.rs | 14 ++-- crates/nu-command/src/formats/from/url.rs | 4 +- crates/nu-command/src/formats/from/yaml.rs | 7 +- crates/nu-command/src/formats/to/command.rs | 4 +- crates/nu-command/src/formats/to/json.rs | 6 +- crates/nu-command/src/math/abs.rs | 4 +- crates/nu-command/src/math/avg.rs | 4 +- crates/nu-command/src/math/ceil.rs | 4 +- crates/nu-command/src/math/command.rs | 4 +- crates/nu-command/src/math/eval.rs | 14 ++-- crates/nu-command/src/math/floor.rs | 4 +- crates/nu-command/src/math/max.rs | 4 +- crates/nu-command/src/math/median.rs | 4 +- crates/nu-command/src/math/min.rs | 4 +- crates/nu-command/src/math/mode.rs | 4 +- crates/nu-command/src/math/product.rs | 4 +- crates/nu-command/src/math/round.rs | 18 +++-- crates/nu-command/src/math/sqrt.rs | 4 +- crates/nu-command/src/math/stddev.rs | 10 ++- crates/nu-command/src/math/sum.rs | 4 +- crates/nu-command/src/math/variance.rs | 6 +- crates/nu-command/src/strings/build_string.rs | 7 +- .../nu-command/src/strings/format/command.rs | 14 ++-- crates/nu-command/src/strings/parse.rs | 5 +- crates/nu-command/src/strings/size.rs | 4 +- crates/nu-command/src/strings/split/chars.rs | 4 +- crates/nu-command/src/strings/split/column.rs | 3 +- .../nu-command/src/strings/split/command.rs | 4 +- crates/nu-command/src/strings/split/row.rs | 14 ++-- .../nu-command/src/strings/str_/capitalize.rs | 13 ++-- .../src/strings/str_/case/camel_case.rs | 16 +++-- .../src/strings/str_/case/command.rs | 4 +- .../src/strings/str_/case/kebab_case.rs | 16 +++-- .../src/strings/str_/case/pascal_case.rs | 16 +++-- .../strings/str_/case/screaming_snake_case.rs | 16 +++-- .../src/strings/str_/case/snake_case.rs | 16 +++-- crates/nu-command/src/strings/str_/collect.rs | 15 +++-- .../nu-command/src/strings/str_/contains.rs | 2 + .../nu-command/src/strings/str_/downcase.rs | 13 ++-- .../nu-command/src/strings/str_/ends_with.rs | 2 + .../src/strings/str_/find_replace.rs | 2 + .../nu-command/src/strings/str_/index_of.rs | 2 + crates/nu-command/src/strings/str_/length.rs | 13 ++-- crates/nu-command/src/strings/str_/lpad.rs | 3 + crates/nu-command/src/strings/str_/reverse.rs | 13 ++-- crates/nu-command/src/strings/str_/rpad.rs | 2 + .../src/strings/str_/starts_with.rs | 2 + crates/nu-command/src/system/benchmark.rs | 14 ++-- crates/nu-command/src/system/ps.rs | 3 +- crates/nu-command/src/system/run_external.rs | 7 +- crates/nu-command/src/system/sys.rs | 3 +- crates/nu-command/src/viewers/griddle.rs | 3 +- crates/nu-command/src/viewers/table.rs | 6 +- crates/nu-engine/src/eval.rs | 64 +++++++++++++++++- crates/nu-plugin/schema/plugin.capnp | 17 +++++ crates/nu-plugin/src/plugin_capnp.rs | 67 +++++++++++++++++++ crates/nu-plugin/src/serializers/signature.rs | 46 +++++++++++-- crates/nu-protocol/src/signature.rs | 49 ++++++++++++++ 118 files changed, 739 insertions(+), 335 deletions(-) diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index b0eecf013..dffed7543 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::{Call, CellPath}, engine::{Command, EngineState, Stack}, - Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, }; #[derive(Clone)] @@ -14,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("into binary").rest( - "rest", - SyntaxShape::CellPath, - "column paths to convert to binary (for table input)", - ) + Signature::build("into binary") + .rest( + "rest", + SyntaxShape::CellPath, + "column paths to convert to binary (for table input)", + ) + .category(Category::Conversions) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/conversions/into/command.rs b/crates/nu-command/src/conversions/into/command.rs index 605401058..9fa1ec600 100644 --- a/crates/nu-command/src/conversions/into/command.rs +++ b/crates/nu-command/src/conversions/into/command.rs @@ -2,7 +2,7 @@ use nu_engine::get_full_help; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - IntoPipelineData, PipelineData, Signature, Value, + Category, IntoPipelineData, PipelineData, Signature, Value, }; #[derive(Clone)] @@ -14,7 +14,7 @@ impl Command for Into { } fn signature(&self) -> Signature { - Signature::build("into") + Signature::build("into").category(Category::Conversions) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/conversions/into/filesize.rs b/crates/nu-command/src/conversions/into/filesize.rs index 6336c7219..795dff7ee 100644 --- a/crates/nu-command/src/conversions/into/filesize.rs +++ b/crates/nu-command/src/conversions/into/filesize.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::{Call, CellPath}, engine::{Command, EngineState, Stack}, - Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, }; #[derive(Clone)] @@ -14,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("into filesize").rest( - "rest", - SyntaxShape::CellPath, - "column paths to convert to filesize (for table input)", - ) + Signature::build("into filesize") + .rest( + "rest", + SyntaxShape::CellPath, + "column paths to convert to filesize (for table input)", + ) + .category(Category::Conversions) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index 8c0914c78..e6185dabb 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::{Call, CellPath}, engine::{Command, EngineState, Stack}, - Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, }; #[derive(Clone)] @@ -14,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("into int").rest( - "rest", - SyntaxShape::CellPath, - "column paths to convert to int (for table input)", - ) + Signature::build("into int") + .rest( + "rest", + SyntaxShape::CellPath, + "column paths to convert to int (for table input)", + ) + .category(Category::Conversions) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 318d33534..842edc6da 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::{Call, CellPath}, engine::{Command, EngineState, Stack}, - Config, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Config, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, }; // TODO num_format::SystemLocale once platform-specific dependencies are stable (see Cargo.toml) @@ -29,6 +29,7 @@ impl Command for SubCommand { "decimal digits to which to round", Some('d'), ) + .category(Category::Conversions) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/core_commands/alias.rs b/crates/nu-command/src/core_commands/alias.rs index ae09d5228..158a3e9de 100644 --- a/crates/nu-command/src/core_commands/alias.rs +++ b/crates/nu-command/src/core_commands/alias.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Alias; @@ -22,6 +22,7 @@ impl Command for Alias { SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)), "equals sign followed by value", ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/def.rs b/crates/nu-command/src/core_commands/def.rs index 6632c1e73..63d07c422 100644 --- a/crates/nu-command/src/core_commands/def.rs +++ b/crates/nu-command/src/core_commands/def.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Def; @@ -23,6 +23,7 @@ impl Command for Def { SyntaxShape::Block(Some(vec![])), "body of the definition", ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/do_.rs b/crates/nu-command/src/core_commands/do_.rs index 92ac299f7..f85f34746 100644 --- a/crates/nu-command/src/core_commands/do_.rs +++ b/crates/nu-command/src/core_commands/do_.rs @@ -1,7 +1,7 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape, Value}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape, Value}; #[derive(Clone)] pub struct Do; @@ -24,6 +24,7 @@ impl Command for Do { "the block to run", ) .rest("rest", SyntaxShape::Any, "the parameter(s) for the block") + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/echo.rs b/crates/nu-command/src/core_commands/echo.rs index be7f231fb..06a1ff1ed 100644 --- a/crates/nu-command/src/core_commands/echo.rs +++ b/crates/nu-command/src/core_commands/echo.rs @@ -1,7 +1,9 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value, ValueStream}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value, ValueStream, +}; #[derive(Clone)] pub struct Echo; @@ -16,7 +18,9 @@ impl Command for Echo { } fn signature(&self) -> Signature { - Signature::build("echo").rest("rest", SyntaxShape::Any, "the values to echo") + Signature::build("echo") + .rest("rest", SyntaxShape::Any, "the values to echo") + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/export.rs b/crates/nu-command/src/core_commands/export.rs index 704b7d59b..93e3f91cd 100644 --- a/crates/nu-command/src/core_commands/export.rs +++ b/crates/nu-command/src/core_commands/export.rs @@ -2,7 +2,7 @@ use nu_engine::get_full_help; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - IntoPipelineData, PipelineData, Signature, Value, + Category, IntoPipelineData, PipelineData, Signature, Value, }; #[derive(Clone)] @@ -14,7 +14,7 @@ impl Command for ExportCommand { } fn signature(&self) -> Signature { - Signature::build("export") + Signature::build("export").category(Category::Core) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/core_commands/export_def.rs b/crates/nu-command/src/core_commands/export_def.rs index e0da0ad07..79d7c2bff 100644 --- a/crates/nu-command/src/core_commands/export_def.rs +++ b/crates/nu-command/src/core_commands/export_def.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct ExportDef; @@ -23,6 +23,7 @@ impl Command for ExportDef { SyntaxShape::Block(Some(vec![])), "body of the definition", ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/export_env.rs b/crates/nu-command/src/core_commands/export_env.rs index 1cfb1d009..261a97b3a 100644 --- a/crates/nu-command/src/core_commands/export_env.rs +++ b/crates/nu-command/src/core_commands/export_env.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct ExportEnv; @@ -26,6 +26,7 @@ impl Command for ExportEnv { SyntaxShape::Block(Some(vec![])), "body of the environment variable definition", ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/for_.rs b/crates/nu-command/src/core_commands/for_.rs index 6435b7696..13343db25 100644 --- a/crates/nu-command/src/core_commands/for_.rs +++ b/crates/nu-command/src/core_commands/for_.rs @@ -2,7 +2,8 @@ use nu_engine::{eval_block, eval_expression}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, SyntaxShape, Value, + Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, SyntaxShape, + Value, }; #[derive(Clone)] @@ -35,6 +36,7 @@ impl Command for For { "the block to run", ) .creates_scope() + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/help.rs b/crates/nu-command/src/core_commands/help.rs index 534a36978..bad246f87 100644 --- a/crates/nu-command/src/core_commands/help.rs +++ b/crates/nu-command/src/core_commands/help.rs @@ -1,8 +1,8 @@ use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - span, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, - Signature, Spanned, SyntaxShape, Value, + span, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, + ShellError, Signature, Spanned, SyntaxShape, Value, }; use nu_engine::{get_full_help, CallExt}; @@ -28,6 +28,7 @@ impl Command for Help { "string to find in command usage", Some('f'), ) + .category(Category::Core) } fn usage(&self) -> &str { @@ -107,6 +108,12 @@ fn help( span: head, }); + cols.push("category".into()); + vals.push(Value::String { + val: cmd.0.category.to_string(), + span: head, + }); + cols.push("usage".into()); vals.push(Value::String { val: c, span: head }); @@ -144,6 +151,12 @@ fn help( span: head, }); + cols.push("category".into()); + vals.push(Value::String { + val: cmd.0.category.to_string(), + span: head, + }); + cols.push("usage".into()); vals.push(Value::String { val: c, span: head }); diff --git a/crates/nu-command/src/core_commands/hide.rs b/crates/nu-command/src/core_commands/hide.rs index 8d28509ef..700280e66 100644 --- a/crates/nu-command/src/core_commands/hide.rs +++ b/crates/nu-command/src/core_commands/hide.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Hide; @@ -10,12 +10,14 @@ impl Command for Hide { "hide" } - fn usage(&self) -> &str { - "Hide definitions in the current scope" + fn signature(&self) -> nu_protocol::Signature { + Signature::build("hide") + .required("pattern", SyntaxShape::String, "import pattern") + .category(Category::Core) } - fn signature(&self) -> nu_protocol::Signature { - Signature::build("hide").required("pattern", SyntaxShape::String, "import pattern") + fn usage(&self) -> &str { + "Hide definitions in the current scope" } fn run( diff --git a/crates/nu-command/src/core_commands/if_.rs b/crates/nu-command/src/core_commands/if_.rs index dc3e8c7ad..9de1bb176 100644 --- a/crates/nu-command/src/core_commands/if_.rs +++ b/crates/nu-command/src/core_commands/if_.rs @@ -1,7 +1,9 @@ use nu_engine::{eval_block, eval_expression}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value}; +use nu_protocol::{ + Category, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, +}; #[derive(Clone)] pub struct If; @@ -24,6 +26,7 @@ impl Command for If { SyntaxShape::Keyword(b"else".to_vec(), Box::new(SyntaxShape::Expression)), "optional else followed by else block", ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/let_.rs b/crates/nu-command/src/core_commands/let_.rs index 5cd254a06..5742f1a23 100644 --- a/crates/nu-command/src/core_commands/let_.rs +++ b/crates/nu-command/src/core_commands/let_.rs @@ -1,7 +1,7 @@ use nu_engine::eval_expression; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Let; @@ -23,6 +23,7 @@ impl Command for Let { SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)), "equals sign followed by value", ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/module.rs b/crates/nu-command/src/core_commands/module.rs index 3f8f12105..fbdc06729 100644 --- a/crates/nu-command/src/core_commands/module.rs +++ b/crates/nu-command/src/core_commands/module.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Module; @@ -22,6 +22,7 @@ impl Command for Module { SyntaxShape::Block(Some(vec![])), "body of the module", ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/register.rs b/crates/nu-command/src/core_commands/register.rs index c5fee5a22..e60e2bd3b 100644 --- a/crates/nu-command/src/core_commands/register.rs +++ b/crates/nu-command/src/core_commands/register.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Register; @@ -15,11 +15,13 @@ impl Command for Register { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("register").required( - "plugin", - SyntaxShape::Filepath, - "location of bin for plugin", - ) + Signature::build("register") + .required( + "plugin", + SyntaxShape::Filepath, + "location of bin for plugin", + ) + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/core_commands/source.rs b/crates/nu-command/src/core_commands/source.rs index d60f330d3..b4626e5e3 100644 --- a/crates/nu-command/src/core_commands/source.rs +++ b/crates/nu-command/src/core_commands/source.rs @@ -1,7 +1,7 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape}; /// Source a file for environment variables. #[derive(Clone)] @@ -13,11 +13,13 @@ impl Command for Source { } fn signature(&self) -> Signature { - Signature::build("source").required( - "filename", - SyntaxShape::Filepath, - "the filepath to the script file to source", - ) + Signature::build("source") + .required( + "filename", + SyntaxShape::Filepath, + "the filepath to the script file to source", + ) + .category(Category::Core) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/core_commands/use_.rs b/crates/nu-command/src/core_commands/use_.rs index 06b60df5a..368af53ea 100644 --- a/crates/nu-command/src/core_commands/use_.rs +++ b/crates/nu-command/src/core_commands/use_.rs @@ -1,7 +1,7 @@ use nu_engine::eval_block; use nu_protocol::ast::{Call, Expr, Expression, ImportPatternMember}; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, Span, SyntaxShape}; +use nu_protocol::{Category, PipelineData, ShellError, Signature, Span, SyntaxShape}; #[derive(Clone)] pub struct Use; @@ -16,7 +16,9 @@ impl Command for Use { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("use").rest("pattern", SyntaxShape::String, "import pattern parts") + Signature::build("use") + .rest("pattern", SyntaxShape::String, "import pattern parts") + .category(Category::Core) } fn run( diff --git a/crates/nu-command/src/date/command.rs b/crates/nu-command/src/date/command.rs index 3206b3b7c..86329ceb0 100644 --- a/crates/nu-command/src/date/command.rs +++ b/crates/nu-command/src/date/command.rs @@ -2,7 +2,7 @@ use nu_engine::get_full_help; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - IntoPipelineData, PipelineData, ShellError, Signature, Value, + Category, IntoPipelineData, PipelineData, ShellError, Signature, Value, }; #[derive(Clone)] @@ -14,7 +14,7 @@ impl Command for Date { } fn signature(&self) -> Signature { - Signature::build("date") + Signature::build("date").category(Category::Date) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/date/format.rs b/crates/nu-command/src/date/format.rs index abee6653d..33e14af10 100644 --- a/crates/nu-command/src/date/format.rs +++ b/crates/nu-command/src/date/format.rs @@ -3,7 +3,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - Example, PipelineData, Signature, Span, Spanned, SyntaxShape, Value, + Category, Example, PipelineData, Signature, Span, Spanned, SyntaxShape, Value, }; use super::utils::{parse_date_from_string, unsupported_input_error}; @@ -17,11 +17,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("date format").required( - "format string", - SyntaxShape::String, - "the desired date format", - ) + Signature::build("date format") + .required( + "format string", + SyntaxShape::String, + "the desired date format", + ) + .category(Category::Date) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/date/humanize.rs b/crates/nu-command/src/date/humanize.rs index 52abbd653..6f4087b83 100644 --- a/crates/nu-command/src/date/humanize.rs +++ b/crates/nu-command/src/date/humanize.rs @@ -3,7 +3,7 @@ use chrono::{DateTime, FixedOffset, Local}; use chrono_humanize::HumanTime; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("date humanize") + Signature::build("date humanize").category(Category::Date) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/date/list_timezone.rs b/crates/nu-command/src/date/list_timezone.rs index 7e4ba8ee7..111439817 100644 --- a/crates/nu-command/src/date/list_timezone.rs +++ b/crates/nu-command/src/date/list_timezone.rs @@ -1,7 +1,7 @@ use chrono_tz::TZ_VARIANTS; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoInterruptiblePipelineData, PipelineData, Signature, Value}; +use nu_protocol::{Category, IntoInterruptiblePipelineData, PipelineData, Signature, Value}; #[derive(Clone)] pub struct SubCommand; @@ -12,7 +12,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("date list-timezone") + Signature::build("date list-timezone").category(Category::Date) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/date/now.rs b/crates/nu-command/src/date/now.rs index dbd0f081f..406993833 100644 --- a/crates/nu-command/src/date/now.rs +++ b/crates/nu-command/src/date/now.rs @@ -1,7 +1,7 @@ use chrono::Local; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, Signature, Value}; +use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, Value}; #[derive(Clone)] pub struct SubCommand; @@ -11,7 +11,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("date now") + Signature::build("date now").category(Category::Date) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/date/to_table.rs b/crates/nu-command/src/date/to_table.rs index 91bd59af4..f518d010d 100644 --- a/crates/nu-command/src/date/to_table.rs +++ b/crates/nu-command/src/date/to_table.rs @@ -2,7 +2,7 @@ use crate::date::utils::{parse_date_from_string, unsupported_input_error}; use chrono::{DateTime, Datelike, FixedOffset, Local, Timelike}; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("date to-table") + Signature::build("date to-table").category(Category::Date) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/date/to_timezone.rs b/crates/nu-command/src/date/to_timezone.rs index c00f4711e..593211ffd 100644 --- a/crates/nu-command/src/date/to_timezone.rs +++ b/crates/nu-command/src/date/to_timezone.rs @@ -5,7 +5,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, + Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, }; use chrono::{FixedOffset, TimeZone}; @@ -19,11 +19,9 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("date to-timezone").required( - "time zone", - SyntaxShape::String, - "time zone description", - ) + Signature::build("date to-timezone") + .required("time zone", SyntaxShape::String, "time zone description") + .category(Category::Date) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/env/let_env.rs b/crates/nu-command/src/env/let_env.rs index b67ebac1c..201b0e605 100644 --- a/crates/nu-command/src/env/let_env.rs +++ b/crates/nu-command/src/env/let_env.rs @@ -1,7 +1,7 @@ use nu_engine::eval_expression; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct LetEnv; @@ -23,6 +23,7 @@ impl Command for LetEnv { SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::String)), "equals sign followed by value", ) + .category(Category::Env) } fn run( diff --git a/crates/nu-command/src/env/with_env.rs b/crates/nu-command/src/env/with_env.rs index 8d5e18c07..3f9b3aeec 100644 --- a/crates/nu-command/src/env/with_env.rs +++ b/crates/nu-command/src/env/with_env.rs @@ -7,7 +7,7 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - Example, PipelineData, ShellError, Signature, SyntaxShape, Value, + Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value, }; #[derive(Clone)] @@ -30,6 +30,7 @@ impl Command for WithEnv { SyntaxShape::Block(Some(vec![SyntaxShape::Any])), "the block to run once the variable is set", ) + .category(Category::Env) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/experimental/git.rs b/crates/nu-command/src/experimental/git.rs index b3939116d..ab3843133 100644 --- a/crates/nu-command/src/experimental/git.rs +++ b/crates/nu-command/src/experimental/git.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, Signature, Value}; +use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, Value}; #[derive(Clone)] pub struct Git; @@ -15,7 +15,7 @@ impl Command for Git { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("git") + Signature::build("git").category(Category::Experimental) } fn run( diff --git a/crates/nu-command/src/experimental/git_checkout.rs b/crates/nu-command/src/experimental/git_checkout.rs index ba55ae6f3..ba3834e22 100644 --- a/crates/nu-command/src/experimental/git_checkout.rs +++ b/crates/nu-command/src/experimental/git_checkout.rs @@ -1,7 +1,7 @@ use nu_engine::eval_expression; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value}; +use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, SyntaxShape, Value}; #[derive(Clone)] pub struct GitCheckout; @@ -16,11 +16,13 @@ impl Command for GitCheckout { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("git checkout").required( - "branch", - SyntaxShape::Custom(Box::new(SyntaxShape::String), "list-git-branches".into()), - "the branch to checkout", - ) + Signature::build("git checkout") + .required( + "branch", + SyntaxShape::Custom(Box::new(SyntaxShape::String), "list-git-branches".into()), + "the branch to checkout", + ) + .category(Category::Experimental) } fn run( diff --git a/crates/nu-command/src/experimental/list_git_branches.rs b/crates/nu-command/src/experimental/list_git_branches.rs index bde67c017..9a2fed515 100644 --- a/crates/nu-command/src/experimental/list_git_branches.rs +++ b/crates/nu-command/src/experimental/list_git_branches.rs @@ -7,6 +7,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::Command; use nu_protocol::engine::EngineState; use nu_protocol::engine::Stack; +use nu_protocol::Category; use nu_protocol::IntoInterruptiblePipelineData; use nu_protocol::PipelineData; use nu_protocol::{Signature, Value}; @@ -25,7 +26,7 @@ impl Command for ListGitBranches { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("list-git-branches") + Signature::build("list-git-branches").category(Category::Experimental) } fn run( diff --git a/crates/nu-command/src/filesystem/cd.rs b/crates/nu-command/src/filesystem/cd.rs index 215ef38b6..ea6a00bed 100644 --- a/crates/nu-command/src/filesystem/cd.rs +++ b/crates/nu-command/src/filesystem/cd.rs @@ -1,7 +1,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Cd; @@ -16,7 +16,9 @@ impl Command for Cd { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("cd").optional("path", SyntaxShape::Filepath, "the path to change to") + Signature::build("cd") + .optional("path", SyntaxShape::Filepath, "the path to change to") + .category(Category::FileSystem) } fn run( diff --git a/crates/nu-command/src/filesystem/cp.rs b/crates/nu-command/src/filesystem/cp.rs index a553a8426..6f6b4f7d4 100644 --- a/crates/nu-command/src/filesystem/cp.rs +++ b/crates/nu-command/src/filesystem/cp.rs @@ -6,7 +6,7 @@ use nu_engine::CallExt; use nu_path::canonicalize_with; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape}; use crate::filesystem::util::FileStructure; @@ -34,6 +34,7 @@ impl Command for Cp { ) .switch("force", "suppress error when no file", Some('f')) .switch("interactive", "ask user to confirm action", Some('i')) + .category(Category::FileSystem) } fn run( diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index 3dfc6975f..dbf16057b 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -3,7 +3,9 @@ use lscolors::{LsColors, Style}; use nu_engine::eval_expression; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoInterruptiblePipelineData, PipelineData, Signature, SyntaxShape, Value}; +use nu_protocol::{ + Category, IntoInterruptiblePipelineData, PipelineData, Signature, SyntaxShape, Value, +}; #[derive(Clone)] pub struct Ls; @@ -19,11 +21,13 @@ impl Command for Ls { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("ls").optional( - "pattern", - SyntaxShape::GlobPattern, - "the glob pattern to use", - ) + Signature::build("ls") + .optional( + "pattern", + SyntaxShape::GlobPattern, + "the glob pattern to use", + ) + .category(Category::FileSystem) } fn run( diff --git a/crates/nu-command/src/filesystem/mkdir.rs b/crates/nu-command/src/filesystem/mkdir.rs index df0beaa80..741dff715 100644 --- a/crates/nu-command/src/filesystem/mkdir.rs +++ b/crates/nu-command/src/filesystem/mkdir.rs @@ -5,7 +5,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, + Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, SyntaxShape, + Value, }; #[derive(Clone)] @@ -24,6 +25,7 @@ impl Command for Mkdir { "the name(s) of the path(s) to create", ) .switch("show-created-paths", "show the path(s) created.", Some('s')) + .category(Category::FileSystem) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filesystem/mv.rs b/crates/nu-command/src/filesystem/mv.rs index fe5262720..777ac231b 100644 --- a/crates/nu-command/src/filesystem/mv.rs +++ b/crates/nu-command/src/filesystem/mv.rs @@ -5,7 +5,7 @@ use super::util::get_interactive_confirmation; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape}; #[derive(Clone)] pub struct Mv; @@ -34,6 +34,7 @@ impl Command for Mv { ) .switch("interactive", "ask user to confirm action", Some('i')) .switch("force", "suppress error when no file", Some('f')) + .category(Category::FileSystem) } fn run( diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index 7c83b0bcc..faea33e58 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -9,7 +9,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, + Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, SyntaxShape, + Value, }; #[derive(Clone)] @@ -55,6 +56,7 @@ impl Command for Rm { SyntaxShape::GlobPattern, "the file path(s) to remove", ) + .category(Category::FileSystem) } fn run( diff --git a/crates/nu-command/src/filesystem/touch.rs b/crates/nu-command/src/filesystem/touch.rs index 0bc66dc06..ece811c97 100644 --- a/crates/nu-command/src/filesystem/touch.rs +++ b/crates/nu-command/src/filesystem/touch.rs @@ -3,7 +3,7 @@ use std::fs::OpenOptions; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape}; #[derive(Clone)] pub struct Touch; @@ -21,6 +21,7 @@ impl Command for Touch { "the path of the file you want to create", ) .rest("rest", SyntaxShape::Filepath, "additional files to create") + .category(Category::FileSystem) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/collect.rs b/crates/nu-command/src/filters/collect.rs index 07074c060..b7dd98125 100644 --- a/crates/nu-command/src/filters/collect.rs +++ b/crates/nu-command/src/filters/collect.rs @@ -1,7 +1,7 @@ use nu_engine::eval_block; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, Signature, SyntaxShape, Value}; +use nu_protocol::{Category, Example, PipelineData, Signature, SyntaxShape, Value}; #[derive(Clone)] pub struct Collect; @@ -12,11 +12,13 @@ impl Command for Collect { } fn signature(&self) -> Signature { - Signature::build("collect").required( - "block", - SyntaxShape::Block(Some(vec![SyntaxShape::Any])), - "the block to run once the stream is collected", - ) + Signature::build("collect") + .required( + "block", + SyntaxShape::Block(Some(vec![SyntaxShape::Any])), + "the block to run once the stream is collected", + ) + .category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/each.rs b/crates/nu-command/src/filters/each.rs index 22a1ebaa7..533f81c78 100644 --- a/crates/nu-command/src/filters/each.rs +++ b/crates/nu-command/src/filters/each.rs @@ -2,8 +2,8 @@ use nu_engine::eval_block; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, Span, - SyntaxShape, Value, + Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, + Span, SyntaxShape, Value, }; #[derive(Clone)] @@ -26,6 +26,7 @@ impl Command for Each { "the block to run", ) .switch("numbered", "iterate with an index", Some('n')) + .category(Category::Filters) } fn examples(&self) -> Vec { diff --git a/crates/nu-command/src/filters/first.rs b/crates/nu-command/src/filters/first.rs index 1d2275984..d3358ff9d 100644 --- a/crates/nu-command/src/filters/first.rs +++ b/crates/nu-command/src/filters/first.rs @@ -2,7 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, + Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, + Type, Value, }; #[derive(Clone)] @@ -14,11 +15,13 @@ impl Command for First { } fn signature(&self) -> Signature { - Signature::build("first").optional( - "rows", - SyntaxShape::Int, - "starting from the front, the number of rows to return", - ) + Signature::build("first") + .optional( + "rows", + SyntaxShape::Int, + "starting from the front, the number of rows to return", + ) + .category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/get.rs b/crates/nu-command/src/filters/get.rs index ffaf6a98a..776667b50 100644 --- a/crates/nu-command/src/filters/get.rs +++ b/crates/nu-command/src/filters/get.rs @@ -1,7 +1,7 @@ use nu_engine::CallExt; use nu_protocol::ast::{Call, CellPath}; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Get; @@ -16,11 +16,13 @@ impl Command for Get { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("get").required( - "cell_path", - SyntaxShape::CellPath, - "the cell path to the data", - ) + Signature::build("get") + .required( + "cell_path", + SyntaxShape::CellPath, + "the cell path to the data", + ) + .category(Category::Filters) } fn run( diff --git a/crates/nu-command/src/filters/last.rs b/crates/nu-command/src/filters/last.rs index 2d9e92939..5dd93e16e 100644 --- a/crates/nu-command/src/filters/last.rs +++ b/crates/nu-command/src/filters/last.rs @@ -3,8 +3,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, - Value, + Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, + SyntaxShape, Value, }; use std::convert::TryInto; @@ -17,11 +17,13 @@ impl Command for Last { } fn signature(&self) -> Signature { - Signature::build("last").optional( - "rows", - SyntaxShape::Int, - "starting from the back, the number of rows to return", - ) + Signature::build("last") + .optional( + "rows", + SyntaxShape::Int, + "starting from the back, the number of rows to return", + ) + .category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/length.rs b/crates/nu-command/src/filters/length.rs index 724018f85..f8bb8229c 100644 --- a/crates/nu-command/src/filters/length.rs +++ b/crates/nu-command/src/filters/length.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, Signature, Value}; +use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, Value}; #[derive(Clone)] pub struct Length; @@ -15,7 +15,7 @@ impl Command for Length { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("length") + Signature::build("length").category(Category::Filters) } fn run( diff --git a/crates/nu-command/src/filters/lines.rs b/crates/nu-command/src/filters/lines.rs index a4ad8143f..5e282c3f7 100644 --- a/crates/nu-command/src/filters/lines.rs +++ b/crates/nu-command/src/filters/lines.rs @@ -1,6 +1,8 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value}; +use nu_protocol::{ + Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value, +}; #[derive(Clone)] pub struct Lines; @@ -17,7 +19,7 @@ impl Command for Lines { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("lines") + Signature::build("lines").category(Category::Filters) } fn run( diff --git a/crates/nu-command/src/filters/par_each.rs b/crates/nu-command/src/filters/par_each.rs index 95a34ecc1..6e34c3e83 100644 --- a/crates/nu-command/src/filters/par_each.rs +++ b/crates/nu-command/src/filters/par_each.rs @@ -2,8 +2,8 @@ use nu_engine::eval_block; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, SyntaxShape, - Value, + Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, + SyntaxShape, Value, }; use rayon::prelude::*; @@ -27,6 +27,7 @@ impl Command for ParEach { "the block to run", ) .switch("numbered", "iterate with an index", Some('n')) + .category(Category::Filters) } fn examples(&self) -> Vec { diff --git a/crates/nu-command/src/filters/range.rs b/crates/nu-command/src/filters/range.rs index 0280f5182..dce0a6c8a 100644 --- a/crates/nu-command/src/filters/range.rs +++ b/crates/nu-command/src/filters/range.rs @@ -3,8 +3,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, - Value, + Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, + SyntaxShape, Value, }; #[derive(Clone)] @@ -16,11 +16,13 @@ impl Command for Range { } fn signature(&self) -> Signature { - Signature::build("range").optional( - "rows", - SyntaxShape::Range, - "range of rows to return: Eg) 4..7 (=> from 4 to 7)", - ) + Signature::build("range") + .optional( + "rows", + SyntaxShape::Range, + "range of rows to return: Eg) 4..7 (=> from 4 to 7)", + ) + .category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/reverse.rs b/crates/nu-command/src/filters/reverse.rs index c62d1e2bb..3eccf3c1a 100644 --- a/crates/nu-command/src/filters/reverse.rs +++ b/crates/nu-command/src/filters/reverse.rs @@ -1,7 +1,8 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, Value, + Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, + Value, }; #[derive(Clone)] @@ -13,7 +14,7 @@ impl Command for Reverse { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("reverse") + Signature::build("reverse").category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index aedf0378f..4c8d4f9d5 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -2,8 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::{Call, CellPath}; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Signature, - Span, SyntaxShape, Value, + Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, + Signature, Span, SyntaxShape, Value, }; #[derive(Clone)] @@ -15,11 +15,13 @@ impl Command for Select { } fn signature(&self) -> Signature { - Signature::build("select").rest( - "rest", - SyntaxShape::CellPath, - "the columns to select from the table", - ) + Signature::build("select") + .rest( + "rest", + SyntaxShape::CellPath, + "the columns to select from the table", + ) + .category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/shuffle.rs b/crates/nu-command/src/filters/shuffle.rs index f9e3dd75e..4c3f07991 100644 --- a/crates/nu-command/src/filters/shuffle.rs +++ b/crates/nu-command/src/filters/shuffle.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoInterruptiblePipelineData, PipelineData, ShellError, Signature}; +use nu_protocol::{Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature}; use rand::prelude::SliceRandom; use rand::thread_rng; @@ -13,7 +13,7 @@ impl Command for Shuffle { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("shuffle") + Signature::build("shuffle").category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/update.rs b/crates/nu-command/src/filters/update.rs index 5e5b120ae..a6bfdab0d 100644 --- a/crates/nu-command/src/filters/update.rs +++ b/crates/nu-command/src/filters/update.rs @@ -2,7 +2,8 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::ast::{Call, CellPath}; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, + Value, }; #[derive(Clone)] @@ -25,6 +26,7 @@ impl Command for Update { SyntaxShape::Any, "the new value to give the cell(s)", ) + .category(Category::Filters) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/filters/where_.rs b/crates/nu-command/src/filters/where_.rs index 66f6b6fe8..e556b8fef 100644 --- a/crates/nu-command/src/filters/where_.rs +++ b/crates/nu-command/src/filters/where_.rs @@ -1,7 +1,7 @@ use nu_engine::eval_expression; use nu_protocol::ast::{Call, Expr, Expression}; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape}; +use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape}; #[derive(Clone)] pub struct Where; @@ -16,7 +16,9 @@ impl Command for Where { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("where").required("cond", SyntaxShape::RowCondition, "condition") + Signature::build("where") + .required("cond", SyntaxShape::RowCondition, "condition") + .category(Category::Filters) } fn run( diff --git a/crates/nu-command/src/filters/wrap.rs b/crates/nu-command/src/filters/wrap.rs index 48a751858..0c92fbed2 100644 --- a/crates/nu-command/src/filters/wrap.rs +++ b/crates/nu-command/src/filters/wrap.rs @@ -2,7 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, SyntaxShape, Value, + Category, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, + SyntaxShape, Value, }; #[derive(Clone)] @@ -18,7 +19,9 @@ impl Command for Wrap { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("wrap").required("name", SyntaxShape::String, "the name of the column") + Signature::build("wrap") + .required("name", SyntaxShape::String, "the name of the column") + .category(Category::Filters) } fn run( diff --git a/crates/nu-command/src/filters/zip.rs b/crates/nu-command/src/filters/zip.rs index 49b082e76..a0f273ebf 100644 --- a/crates/nu-command/src/filters/zip.rs +++ b/crates/nu-command/src/filters/zip.rs @@ -2,8 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, SyntaxShape, - Value, + Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, + SyntaxShape, Value, }; #[derive(Clone)] @@ -19,7 +19,9 @@ impl Command for Zip { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("zip").required("other", SyntaxShape::Any, "the other input") + Signature::build("zip") + .required("other", SyntaxShape::Any, "the other input") + .category(Category::Filters) } fn examples(&self) -> Vec { diff --git a/crates/nu-command/src/formats/from/command.rs b/crates/nu-command/src/formats/from/command.rs index f8de9bd63..719face4c 100644 --- a/crates/nu-command/src/formats/from/command.rs +++ b/crates/nu-command/src/formats/from/command.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature}; +use nu_protocol::{Category, PipelineData, ShellError, Signature}; #[derive(Clone)] pub struct From; @@ -15,7 +15,7 @@ impl Command for From { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("from") + Signature::build("from").category(Category::Formats) } fn run( diff --git a/crates/nu-command/src/formats/from/csv.rs b/crates/nu-command/src/formats/from/csv.rs index 02b350091..3510a05ad 100644 --- a/crates/nu-command/src/formats/from/csv.rs +++ b/crates/nu-command/src/formats/from/csv.rs @@ -3,7 +3,7 @@ use super::delimited::from_delimited_data; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; #[derive(Clone)] pub struct FromCsv; @@ -26,6 +26,7 @@ impl Command for FromCsv { "don't treat the first row as column names", Some('n'), ) + .category(Category::Formats) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/formats/from/eml.rs b/crates/nu-command/src/formats/from/eml.rs index 9ded63ea6..629db0088 100644 --- a/crates/nu-command/src/formats/from/eml.rs +++ b/crates/nu-command/src/formats/from/eml.rs @@ -4,6 +4,7 @@ use indexmap::map::IndexMap; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::Config; use nu_protocol::{ Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, @@ -20,12 +21,14 @@ impl Command for FromEml { } fn signature(&self) -> Signature { - Signature::build("from eml").named( - "preview-body", - SyntaxShape::Int, - "How many bytes of the body to preview", - Some('b'), - ) + Signature::build("from eml") + .named( + "preview-body", + SyntaxShape::Int, + "How many bytes of the body to preview", + Some('b'), + ) + .category(Category::Formats) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/formats/from/json.rs b/crates/nu-command/src/formats/from/json.rs index 75c6bcfd3..4f8c77144 100644 --- a/crates/nu-command/src/formats/from/json.rs +++ b/crates/nu-command/src/formats/from/json.rs @@ -1,8 +1,8 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Signature, - Span, Value, + Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, + Signature, Span, Value, }; #[derive(Clone)] @@ -18,11 +18,9 @@ impl Command for FromJson { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("from json").switch( - "objects", - "treat each line as a separate value", - Some('o'), - ) + Signature::build("from json") + .switch("objects", "treat each line as a separate value", Some('o')) + .category(Category::Formats) } fn examples(&self) -> Vec { diff --git a/crates/nu-command/src/formats/from/tsv.rs b/crates/nu-command/src/formats/from/tsv.rs index 4f9a2e708..075fab72a 100644 --- a/crates/nu-command/src/formats/from/tsv.rs +++ b/crates/nu-command/src/formats/from/tsv.rs @@ -2,7 +2,7 @@ use super::delimited::from_delimited_data; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Config, PipelineData, ShellError, Signature}; +use nu_protocol::{Category, Config, PipelineData, ShellError, Signature}; #[derive(Clone)] pub struct FromTsv; @@ -13,11 +13,13 @@ impl Command for FromTsv { } fn signature(&self) -> Signature { - Signature::build("from csv").switch( - "noheaders", - "don't treat the first row as column names", - Some('n'), - ) + Signature::build("from csv") + .switch( + "noheaders", + "don't treat the first row as column names", + Some('n'), + ) + .category(Category::Formats) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/formats/from/url.rs b/crates/nu-command/src/formats/from/url.rs index bc113be7b..5d3f4731c 100644 --- a/crates/nu-command/src/formats/from/url.rs +++ b/crates/nu-command/src/formats/from/url.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Config, Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Config, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct FromUrl; @@ -11,7 +11,7 @@ impl Command for FromUrl { } fn signature(&self) -> Signature { - Signature::build("from url") + Signature::build("from url").category(Category::Formats) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/formats/from/yaml.rs b/crates/nu-command/src/formats/from/yaml.rs index 2114a84bd..d463431db 100644 --- a/crates/nu-command/src/formats/from/yaml.rs +++ b/crates/nu-command/src/formats/from/yaml.rs @@ -2,7 +2,8 @@ use itertools::Itertools; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, Value, + Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, + Spanned, Value, }; use serde::de::Deserialize; use std::collections::HashMap; @@ -16,7 +17,7 @@ impl Command for FromYaml { } fn signature(&self) -> Signature { - Signature::build("from yaml") + Signature::build("from yaml").category(Category::Formats) } fn usage(&self) -> &str { @@ -84,7 +85,7 @@ impl Command for FromYml { } fn signature(&self) -> Signature { - Signature::build("from yml") + Signature::build("from yml").category(Category::Formats) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/formats/to/command.rs b/crates/nu-command/src/formats/to/command.rs index 226b7f30e..068d875a5 100644 --- a/crates/nu-command/src/formats/to/command.rs +++ b/crates/nu-command/src/formats/to/command.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature}; +use nu_protocol::{Category, PipelineData, ShellError, Signature}; #[derive(Clone)] pub struct To; @@ -15,7 +15,7 @@ impl Command for To { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("to") + Signature::build("to").category(Category::Formats) } fn run( diff --git a/crates/nu-command/src/formats/to/json.rs b/crates/nu-command/src/formats/to/json.rs index ac08404e0..6988af902 100644 --- a/crates/nu-command/src/formats/to/json.rs +++ b/crates/nu-command/src/formats/to/json.rs @@ -1,8 +1,8 @@ use nu_protocol::ast::{Call, PathMember}; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Signature, - Value, + Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, + Signature, Value, }; #[derive(Clone)] @@ -14,7 +14,7 @@ impl Command for ToJson { } fn signature(&self) -> Signature { - Signature::build("to json") + Signature::build("to json").category(Category::Formats) // .named( // "pretty", // SyntaxShape::Int, diff --git a/crates/nu-command/src/math/abs.rs b/crates/nu-command/src/math/abs.rs index 888317cd2..89341b89a 100644 --- a/crates/nu-command/src/math/abs.rs +++ b/crates/nu-command/src/math/abs.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -11,7 +11,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math abs") + Signature::build("math abs").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/avg.rs b/crates/nu-command/src/math/avg.rs index f7de5be52..a5f6841a7 100644 --- a/crates/nu-command/src/math/avg.rs +++ b/crates/nu-command/src/math/avg.rs @@ -2,7 +2,7 @@ use crate::math::reducers::{reducer_for, Reduce}; use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math avg") + Signature::build("math avg").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/ceil.rs b/crates/nu-command/src/math/ceil.rs index a23720ffb..b9e032ee5 100644 --- a/crates/nu-command/src/math/ceil.rs +++ b/crates/nu-command/src/math/ceil.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -11,7 +11,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math ceil") + Signature::build("math ceil").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/command.rs b/crates/nu-command/src/math/command.rs index 6efc11f87..266a0cc16 100644 --- a/crates/nu-command/src/math/command.rs +++ b/crates/nu-command/src/math/command.rs @@ -2,7 +2,7 @@ use nu_engine::get_full_help; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - IntoPipelineData, PipelineData, Signature, Value, + Category, IntoPipelineData, PipelineData, Signature, Value, }; #[derive(Clone)] @@ -14,7 +14,7 @@ impl Command for MathCommand { } fn signature(&self) -> Signature { - Signature::build("math") + Signature::build("math").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/eval.rs b/crates/nu-command/src/math/eval.rs index b8c79c116..87265b021 100644 --- a/crates/nu-command/src/math/eval.rs +++ b/crates/nu-command/src/math/eval.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, + Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, }; #[derive(Clone)] @@ -18,11 +18,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math eval").optional( - "math expression", - SyntaxShape::String, - "the math expression to evaluate", - ) + Signature::build("math eval") + .optional( + "math expression", + SyntaxShape::String, + "the math expression to evaluate", + ) + .category(Category::Math) } fn run( diff --git a/crates/nu-command/src/math/floor.rs b/crates/nu-command/src/math/floor.rs index ea1e4cbb4..cd8811d11 100644 --- a/crates/nu-command/src/math/floor.rs +++ b/crates/nu-command/src/math/floor.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -11,7 +11,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math floor") + Signature::build("math floor").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/max.rs b/crates/nu-command/src/math/max.rs index efe2422b0..2635192c5 100644 --- a/crates/nu-command/src/math/max.rs +++ b/crates/nu-command/src/math/max.rs @@ -2,7 +2,7 @@ use crate::math::reducers::{reducer_for, Reduce}; use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math max") + Signature::build("math max").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/median.rs b/crates/nu-command/src/math/median.rs index 1204485fc..080c4fc04 100644 --- a/crates/nu-command/src/math/median.rs +++ b/crates/nu-command/src/math/median.rs @@ -2,7 +2,7 @@ use crate::math::avg::average; use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math median") + Signature::build("math median").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/min.rs b/crates/nu-command/src/math/min.rs index a59db60c2..c897f4394 100644 --- a/crates/nu-command/src/math/min.rs +++ b/crates/nu-command/src/math/min.rs @@ -2,7 +2,7 @@ use crate::math::reducers::{reducer_for, Reduce}; use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math min") + Signature::build("math min").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/mode.rs b/crates/nu-command/src/math/mode.rs index baa8f2e73..619a02aec 100644 --- a/crates/nu-command/src/math/mode.rs +++ b/crates/nu-command/src/math/mode.rs @@ -1,7 +1,7 @@ use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; use std::cmp::Ordering; #[derive(Clone)] @@ -36,7 +36,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math mode") + Signature::build("math mode").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/product.rs b/crates/nu-command/src/math/product.rs index bfa2e85cb..563d99137 100644 --- a/crates/nu-command/src/math/product.rs +++ b/crates/nu-command/src/math/product.rs @@ -2,7 +2,7 @@ use crate::math::reducers::{reducer_for, Reduce}; use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math product") + Signature::build("math product").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/round.rs b/crates/nu-command/src/math/round.rs index b83c1f8ee..1b6b9db5f 100644 --- a/crates/nu-command/src/math/round.rs +++ b/crates/nu-command/src/math/round.rs @@ -1,7 +1,9 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, +}; #[derive(Clone)] pub struct SubCommand; @@ -12,12 +14,14 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math round").named( - "precision", - SyntaxShape::Number, - "digits of precision", - Some('p'), - ) + Signature::build("math round") + .named( + "precision", + SyntaxShape::Number, + "digits of precision", + Some('p'), + ) + .category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/sqrt.rs b/crates/nu-command/src/math/sqrt.rs index 70ce9492f..7cb9ca4d1 100644 --- a/crates/nu-command/src/math/sqrt.rs +++ b/crates/nu-command/src/math/sqrt.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -11,7 +11,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math sqrt") + Signature::build("math sqrt").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/stddev.rs b/crates/nu-command/src/math/stddev.rs index 2d7b2393e..f7b231f27 100644 --- a/crates/nu-command/src/math/stddev.rs +++ b/crates/nu-command/src/math/stddev.rs @@ -2,7 +2,7 @@ use super::variance::compute_variance as variance; use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,11 +13,9 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math stddev").switch( - "sample", - "calculate sample standard deviation", - Some('s'), - ) + Signature::build("math stddev") + .switch("sample", "calculate sample standard deviation", Some('s')) + .category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/sum.rs b/crates/nu-command/src/math/sum.rs index 743241aa4..814856dec 100644 --- a/crates/nu-command/src/math/sum.rs +++ b/crates/nu-command/src/math/sum.rs @@ -2,7 +2,7 @@ use crate::math::reducers::{reducer_for, Reduce}; use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math sum") + Signature::build("math sum").category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/math/variance.rs b/crates/nu-command/src/math/variance.rs index a82968201..6252a49f8 100644 --- a/crates/nu-command/src/math/variance.rs +++ b/crates/nu-command/src/math/variance.rs @@ -1,7 +1,7 @@ use crate::math::utils::run_with_function; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Value}; #[derive(Clone)] pub struct SubCommand; @@ -12,7 +12,9 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("math variance").switch("sample", "calculate sample variance", Some('s')) + Signature::build("math variance") + .switch("sample", "calculate sample variance", Some('s')) + .category(Category::Math) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/build_string.rs b/crates/nu-command/src/strings/build_string.rs index 5c6692a3c..9c6abada6 100644 --- a/crates/nu-command/src/strings/build_string.rs +++ b/crates/nu-command/src/strings/build_string.rs @@ -2,7 +2,8 @@ use nu_engine::eval_expression; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, + Value, }; #[derive(Clone)] @@ -18,7 +19,9 @@ impl Command for BuildString { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("build-string").rest("rest", SyntaxShape::String, "list of string") + Signature::build("build-string") + .rest("rest", SyntaxShape::String, "list of string") + .category(Category::Strings) } fn examples(&self) -> Vec { diff --git a/crates/nu-command/src/strings/format/command.rs b/crates/nu-command/src/strings/format/command.rs index 2170dd722..aac42acba 100644 --- a/crates/nu-command/src/strings/format/command.rs +++ b/crates/nu-command/src/strings/format/command.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::{Call, PathMember}; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, ValueStream, + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, ValueStream, }; #[derive(Clone)] @@ -14,11 +14,13 @@ impl Command for Format { } fn signature(&self) -> Signature { - Signature::build("format").required( - "pattern", - SyntaxShape::String, - "the pattern to output. e.g.) \"{foo}: {bar}\"", - ) + Signature::build("format") + .required( + "pattern", + SyntaxShape::String, + "the pattern to output. e.g.) \"{foo}: {bar}\"", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/parse.rs b/crates/nu-command/src/strings/parse.rs index d1cdff0db..bebf0fdc4 100644 --- a/crates/nu-command/src/strings/parse.rs +++ b/crates/nu-command/src/strings/parse.rs @@ -2,8 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, - ValueStream, + Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, + Value, ValueStream, }; use regex::Regex; @@ -27,6 +27,7 @@ impl Command for Parse { "the pattern to match. Eg) \"{foo}: {bar}\"", ) .switch("regex", "use full regex syntax for patterns", Some('r')) + .category(Category::Strings) } fn examples(&self) -> Vec { diff --git a/crates/nu-command/src/strings/size.rs b/crates/nu-command/src/strings/size.rs index c8307845c..dd72d766b 100644 --- a/crates/nu-command/src/strings/size.rs +++ b/crates/nu-command/src/strings/size.rs @@ -4,7 +4,7 @@ use unicode_segmentation::UnicodeSegmentation; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Type, Value}; +use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Type, Value}; #[derive(Clone)] pub struct Size; @@ -15,7 +15,7 @@ impl Command for Size { } fn signature(&self) -> Signature { - Signature::build("size") + Signature::build("size").category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/split/chars.rs b/crates/nu-command/src/strings/split/chars.rs index bfd48a2d8..1a03e1f13 100644 --- a/crates/nu-command/src/strings/split/chars.rs +++ b/crates/nu-command/src/strings/split/chars.rs @@ -1,7 +1,7 @@ use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - Example, PipelineData, ShellError, Signature, Span, Type, Value, + Category, Example, PipelineData, ShellError, Signature, Span, Type, Value, }; #[derive(Clone)] @@ -13,7 +13,7 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("split chars") + Signature::build("split chars").category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/split/column.rs b/crates/nu-command/src/strings/split/column.rs index dbdfa28e1..4144b397b 100644 --- a/crates/nu-command/src/strings/split/column.rs +++ b/crates/nu-command/src/strings/split/column.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, + Category, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -26,6 +26,7 @@ impl Command for SubCommand { SyntaxShape::String, "column names to give the new columns", ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/split/command.rs b/crates/nu-command/src/strings/split/command.rs index e6b30b3cc..60ab4f31a 100644 --- a/crates/nu-command/src/strings/split/command.rs +++ b/crates/nu-command/src/strings/split/command.rs @@ -2,7 +2,7 @@ use nu_engine::get_full_help; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - IntoPipelineData, PipelineData, Signature, Value, + Category, IntoPipelineData, PipelineData, Signature, Value, }; #[derive(Clone)] @@ -14,7 +14,7 @@ impl Command for SplitCommand { } fn signature(&self) -> Signature { - Signature::build("split") + Signature::build("split").category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/split/row.rs b/crates/nu-command/src/strings/split/row.rs index b5ada3f14..8374bb3a0 100644 --- a/crates/nu-command/src/strings/split/row.rs +++ b/crates/nu-command/src/strings/split/row.rs @@ -2,7 +2,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, + Category, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, }; #[derive(Clone)] @@ -14,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("split row").required( - "separator", - SyntaxShape::String, - "the character that denotes what separates rows", - ) + Signature::build("split row") + .required( + "separator", + SyntaxShape::String, + "the character that denotes what separates rows", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/capitalize.rs b/crates/nu-command/src/strings/str_/capitalize.rs index 91b3e6d59..e674a4306 100644 --- a/crates/nu-command/src/strings/str_/capitalize.rs +++ b/crates/nu-command/src/strings/str_/capitalize.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; #[derive(Clone)] @@ -13,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str capitalize").rest( - "rest", - SyntaxShape::CellPath, - "optionally capitalize text by column paths", - ) + Signature::build("str capitalize") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally capitalize text by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/case/camel_case.rs b/crates/nu-command/src/strings/str_/case/camel_case.rs index 9c201937e..db545453d 100644 --- a/crates/nu-command/src/strings/str_/case/camel_case.rs +++ b/crates/nu-command/src/strings/str_/case/camel_case.rs @@ -1,7 +1,9 @@ use inflector::cases::camelcase::to_camel_case; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, +}; use crate::operate; @@ -14,11 +16,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str camel-case").rest( - "rest", - SyntaxShape::CellPath, - "optionally convert text to camelCase by column paths", - ) + Signature::build("str camel-case") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally convert text to camelCase by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/case/command.rs b/crates/nu-command/src/strings/str_/case/command.rs index 40c038c7a..ac43e6a9b 100644 --- a/crates/nu-command/src/strings/str_/case/command.rs +++ b/crates/nu-command/src/strings/str_/case/command.rs @@ -2,7 +2,7 @@ use nu_engine::get_full_help; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - IntoPipelineData, PipelineData, Signature, Value, + Category, IntoPipelineData, PipelineData, Signature, Value, }; #[derive(Clone)] @@ -14,7 +14,7 @@ impl Command for Str { } fn signature(&self) -> Signature { - Signature::build("str") + Signature::build("str").category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/case/kebab_case.rs b/crates/nu-command/src/strings/str_/case/kebab_case.rs index 9cc6f9c15..a1afc324c 100644 --- a/crates/nu-command/src/strings/str_/case/kebab_case.rs +++ b/crates/nu-command/src/strings/str_/case/kebab_case.rs @@ -1,7 +1,9 @@ use inflector::cases::kebabcase::to_kebab_case; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, +}; use crate::operate; @@ -14,11 +16,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str kebab-case").rest( - "rest", - SyntaxShape::CellPath, - "optionally convert text to kebab-case by column paths", - ) + Signature::build("str kebab-case") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally convert text to kebab-case by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/case/pascal_case.rs b/crates/nu-command/src/strings/str_/case/pascal_case.rs index 5e6deaf40..44dd10006 100644 --- a/crates/nu-command/src/strings/str_/case/pascal_case.rs +++ b/crates/nu-command/src/strings/str_/case/pascal_case.rs @@ -1,7 +1,9 @@ use inflector::cases::pascalcase::to_pascal_case; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, +}; use crate::operate; @@ -14,11 +16,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str pascal-case").rest( - "rest", - SyntaxShape::CellPath, - "optionally convert text to PascalCase by column paths", - ) + Signature::build("str pascal-case") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally convert text to PascalCase by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs b/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs index ef178e66b..e924c1ed6 100644 --- a/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs +++ b/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs @@ -1,7 +1,9 @@ use inflector::cases::screamingsnakecase::to_screaming_snake_case; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, +}; use crate::operate; #[derive(Clone)] @@ -13,11 +15,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str screaming-snake-case").rest( - "rest", - SyntaxShape::CellPath, - "optionally convert text to SCREAMING_SNAKE_CASE by column paths", - ) + Signature::build("str screaming-snake-case") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally convert text to SCREAMING_SNAKE_CASE by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/case/snake_case.rs b/crates/nu-command/src/strings/str_/case/snake_case.rs index f5bc419dd..4a9818677 100644 --- a/crates/nu-command/src/strings/str_/case/snake_case.rs +++ b/crates/nu-command/src/strings/str_/case/snake_case.rs @@ -1,7 +1,9 @@ use inflector::cases::snakecase::to_snake_case; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, +}; use crate::operate; #[derive(Clone)] @@ -13,11 +15,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str snake-case").rest( - "rest", - SyntaxShape::CellPath, - "optionally convert text to snake_case by column paths", - ) + Signature::build("str snake-case") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally convert text to snake_case by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { "converts a string to snake_case" diff --git a/crates/nu-command/src/strings/str_/collect.rs b/crates/nu-command/src/strings/str_/collect.rs index e4b2fead5..af5a3d6f3 100644 --- a/crates/nu-command/src/strings/str_/collect.rs +++ b/crates/nu-command/src/strings/str_/collect.rs @@ -2,7 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, + Value, }; #[derive(Clone)] @@ -14,11 +15,13 @@ impl Command for StrCollect { } fn signature(&self) -> Signature { - Signature::build("str collect").optional( - "separator", - SyntaxShape::String, - "optional separator to use when creating string", - ) + Signature::build("str collect") + .optional( + "separator", + SyntaxShape::String, + "optional separator to use when creating string", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/contains.rs b/crates/nu-command/src/strings/str_/contains.rs index 228f066b1..7d50537a4 100644 --- a/crates/nu-command/src/strings/str_/contains.rs +++ b/crates/nu-command/src/strings/str_/contains.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::{ Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, }; @@ -23,6 +24,7 @@ impl Command for SubCommand { "optionally check if string contains pattern by column paths", ) .switch("insensitive", "search is case insensitive", Some('i')) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/downcase.rs b/crates/nu-command/src/strings/str_/downcase.rs index 88ea405d0..df8127497 100644 --- a/crates/nu-command/src/strings/str_/downcase.rs +++ b/crates/nu-command/src/strings/str_/downcase.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; #[derive(Clone)] @@ -13,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str downcase").rest( - "rest", - SyntaxShape::CellPath, - "optionally downcase text by column paths", - ) + Signature::build("str downcase") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally downcase text by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/ends_with.rs b/crates/nu-command/src/strings/str_/ends_with.rs index 571a4a77b..059ccbd52 100644 --- a/crates/nu-command/src/strings/str_/ends_with.rs +++ b/crates/nu-command/src/strings/str_/ends_with.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::Spanned; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; @@ -21,6 +22,7 @@ impl Command for SubCommand { SyntaxShape::CellPath, "optionally matches suffix of text by column paths", ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/find_replace.rs b/crates/nu-command/src/strings/str_/find_replace.rs index 637b3784a..d486cb66b 100644 --- a/crates/nu-command/src/strings/str_/find_replace.rs +++ b/crates/nu-command/src/strings/str_/find_replace.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::Spanned; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; use regex::Regex; @@ -32,6 +33,7 @@ impl Command for SubCommand { "optionally find and replace text by column paths", ) .switch("all", "replace all occurrences of find string", Some('a')) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index 40ae8e038..af58b3775 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::Spanned; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; use std::sync::Arc; @@ -43,6 +44,7 @@ impl Command for SubCommand { Some('r'), ) .switch("end", "search from the end of the string", Some('e')) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/length.rs b/crates/nu-command/src/strings/str_/length.rs index df082e9a7..4945c88c2 100644 --- a/crates/nu-command/src/strings/str_/length.rs +++ b/crates/nu-command/src/strings/str_/length.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; #[derive(Clone)] @@ -13,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str length").rest( - "rest", - SyntaxShape::CellPath, - "optionally find length of text by column paths", - ) + Signature::build("str length") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally find length of text by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/lpad.rs b/crates/nu-command/src/strings/str_/lpad.rs index dedbcafa7..3ca04d2a8 100644 --- a/crates/nu-command/src/strings/str_/lpad.rs +++ b/crates/nu-command/src/strings/str_/lpad.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; use std::sync::Arc; @@ -33,11 +34,13 @@ impl Command for SubCommand { SyntaxShape::CellPath, "optionally check if string contains pattern by column paths", ) + .category(Category::Strings) } fn usage(&self) -> &str { "pad a string with a character a certain length" } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-command/src/strings/str_/reverse.rs b/crates/nu-command/src/strings/str_/reverse.rs index b2ab3340c..860767151 100644 --- a/crates/nu-command/src/strings/str_/reverse.rs +++ b/crates/nu-command/src/strings/str_/reverse.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; #[derive(Clone)] @@ -13,11 +14,13 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("str reverse").rest( - "rest", - SyntaxShape::CellPath, - "optionally reverse text by column paths", - ) + Signature::build("str reverse") + .rest( + "rest", + SyntaxShape::CellPath, + "optionally reverse text by column paths", + ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/rpad.rs b/crates/nu-command/src/strings/str_/rpad.rs index ebbe17313..181489cee 100644 --- a/crates/nu-command/src/strings/str_/rpad.rs +++ b/crates/nu-command/src/strings/str_/rpad.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; use std::sync::Arc; @@ -33,6 +34,7 @@ impl Command for SubCommand { SyntaxShape::CellPath, "optionally check if string contains pattern by column paths", ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/starts_with.rs b/crates/nu-command/src/strings/str_/starts_with.rs index 4d3392b93..9f26ba3f4 100644 --- a/crates/nu-command/src/strings/str_/starts_with.rs +++ b/crates/nu-command/src/strings/str_/starts_with.rs @@ -2,6 +2,7 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::ast::CellPath; use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::Category; use nu_protocol::Spanned; use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value}; use std::sync::Arc; @@ -28,6 +29,7 @@ impl Command for SubCommand { SyntaxShape::CellPath, "optionally matches prefix of text by column paths", ) + .category(Category::Strings) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/system/benchmark.rs b/crates/nu-command/src/system/benchmark.rs index db9040ebd..0b2f0b13e 100644 --- a/crates/nu-command/src/system/benchmark.rs +++ b/crates/nu-command/src/system/benchmark.rs @@ -3,7 +3,7 @@ use std::time::Instant; use nu_engine::eval_block; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value}; +use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, SyntaxShape, Value}; #[derive(Clone)] pub struct Benchmark; @@ -18,11 +18,13 @@ impl Command for Benchmark { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("benchmark").required( - "block", - SyntaxShape::Block(Some(vec![])), - "the block to run", - ) + Signature::build("benchmark") + .required( + "block", + SyntaxShape::Block(Some(vec![])), + "the block to run", + ) + .category(Category::System) } fn run( diff --git a/crates/nu-command/src/system/ps.rs b/crates/nu-command/src/system/ps.rs index a1f9e904f..ed5d4a6e5 100644 --- a/crates/nu-command/src/system/ps.rs +++ b/crates/nu-command/src/system/ps.rs @@ -1,7 +1,7 @@ use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value, + Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value, }; use sysinfo::{ProcessExt, System, SystemExt}; @@ -22,6 +22,7 @@ impl Command for Ps { Some('l'), ) .filter() + .category(Category::System) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index d0dedaee6..368958882 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -8,7 +8,7 @@ use std::sync::mpsc; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value}; -use nu_protocol::{Config, IntoInterruptiblePipelineData, PipelineData, Span, Spanned}; +use nu_protocol::{Category, Config, IntoInterruptiblePipelineData, PipelineData, Span, Spanned}; use nu_engine::CallExt; @@ -26,10 +26,15 @@ impl Command for External { "Runs external command" } + fn is_private(&self) -> bool { + true + } + fn signature(&self) -> nu_protocol::Signature { Signature::build("run_external") .switch("last_expression", "last_expression", None) .rest("rest", SyntaxShape::Any, "external command to run") + .category(Category::System) } fn run( diff --git a/crates/nu-command/src/system/sys.rs b/crates/nu-command/src/system/sys.rs index 442a4136c..c6c44237e 100644 --- a/crates/nu-command/src/system/sys.rs +++ b/crates/nu-command/src/system/sys.rs @@ -1,7 +1,7 @@ use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value, + Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value, }; use sysinfo::{ComponentExt, DiskExt, NetworkExt, ProcessorExt, System, SystemExt, UserExt}; @@ -17,6 +17,7 @@ impl Command for Sys { Signature::build("sys") .desc("View information about the current system.") .filter() + .category(Category::System) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index e62315696..9085bae48 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -3,7 +3,7 @@ use nu_engine::CallExt; use nu_protocol::{ ast::{Call, PathMember}, engine::{Command, EngineState, Stack}, - Config, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value, + Category, Config, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value, }; use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions}; use terminal_size::{Height, Width}; @@ -35,6 +35,7 @@ impl Command for Griddle { "character to separate grid with", Some('s'), ) + .category(Category::Viewers) } fn extra_usage(&self) -> &str { diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 9a4a7c593..0efe07545 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -1,6 +1,8 @@ use nu_protocol::ast::{Call, PathMember}; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Config, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value}; +use nu_protocol::{ + Category, Config, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value, +}; use nu_table::{StyledString, Theme}; use std::collections::HashMap; use std::sync::atomic::{AtomicBool, Ordering}; @@ -21,7 +23,7 @@ impl Command for Table { } fn signature(&self) -> nu_protocol::Signature { - Signature::build("table") + Signature::build("table").category(Category::Viewers) } fn run( diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index e53d19f61..a08327cc7 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -536,10 +536,72 @@ pub fn eval_variable( } for command in &frame.decls { - commands.push(Value::String { + let mut cols = vec![]; + let mut vals = vec![]; + + cols.push("command".into()); + vals.push(Value::String { val: String::from_utf8_lossy(command.0).to_string(), span, }); + + let decl = engine_state.get_decl(*command.1); + let signature = decl.signature(); + cols.push("category".to_string()); + vals.push(Value::String { + val: signature.category.to_string(), + span, + }); + + cols.push("usage".to_string()); + vals.push(Value::String { + val: decl.usage().into(), + span, + }); + + cols.push("is_binary".to_string()); + vals.push(Value::Bool { + val: decl.is_binary(), + span, + }); + + cols.push("is_private".to_string()); + vals.push(Value::Bool { + val: decl.is_private(), + span, + }); + + cols.push("is_builtin".to_string()); + vals.push(Value::Bool { + val: decl.is_builtin(), + span, + }); + + cols.push("is_sub".to_string()); + vals.push(Value::Bool { + val: decl.is_sub(), + span, + }); + + cols.push("is_plugin".to_string()); + vals.push(Value::Bool { + val: decl.is_plugin(), + span, + }); + + cols.push("creates_scope".to_string()); + vals.push(Value::Bool { + val: signature.creates_scope, + span, + }); + + cols.push("extra_usage".to_string()); + vals.push(Value::String { + val: decl.extra_usage().into(), + span, + }); + + commands.push(Value::Record { cols, vals, span }) } for alias in &frame.aliases { diff --git a/crates/nu-plugin/schema/plugin.capnp b/crates/nu-plugin/schema/plugin.capnp index 2bc2bfd93..27b036d85 100644 --- a/crates/nu-plugin/schema/plugin.capnp +++ b/crates/nu-plugin/schema/plugin.capnp @@ -54,6 +54,23 @@ struct Signature { rest @5 :Argument; # Optional value. Check for existence when deserializing named @6 :List(Flag); isFilter @7 :Bool; + category @8 :Category; +} + +enum Category { + default @0; + conversions @1; + core @2; + date @3; + env @4; + experimental @5; + filesystem @6; + filters @7; + formats @8; + math @9; + strings @10; + system @11; + viewers @12; } struct Flag { diff --git a/crates/nu-plugin/src/plugin_capnp.rs b/crates/nu-plugin/src/plugin_capnp.rs index 19f22aa71..233588151 100644 --- a/crates/nu-plugin/src/plugin_capnp.rs +++ b/crates/nu-plugin/src/plugin_capnp.rs @@ -1652,6 +1652,12 @@ pub mod signature { pub fn get_is_filter(self) -> bool { self.reader.get_bool_field(0) } + #[inline] + pub fn get_category( + self, + ) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.reader.get_data_field::(1)) + } } pub struct Builder<'a> { @@ -1912,6 +1918,16 @@ pub mod signature { pub fn set_is_filter(&mut self, value: bool) { self.builder.set_bool_field(0, value); } + #[inline] + pub fn get_category( + self, + ) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.builder.get_data_field::(1)) + } + #[inline] + pub fn set_category(&mut self, value: crate::plugin_capnp::Category) { + self.builder.set_data_field::(1, value as u16) + } } pub struct Pipeline { @@ -1939,6 +1955,57 @@ pub mod signature { } } +#[repr(u16)] +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Category { + Default = 0, + Conversions = 1, + Core = 2, + Date = 3, + Env = 4, + Experimental = 5, + Filesystem = 6, + Filters = 7, + Formats = 8, + Math = 9, + Strings = 10, + System = 11, + Viewers = 12, +} +impl ::capnp::traits::FromU16 for Category { + #[inline] + fn from_u16(value: u16) -> ::core::result::Result { + match value { + 0 => ::core::result::Result::Ok(Category::Default), + 1 => ::core::result::Result::Ok(Category::Conversions), + 2 => ::core::result::Result::Ok(Category::Core), + 3 => ::core::result::Result::Ok(Category::Date), + 4 => ::core::result::Result::Ok(Category::Env), + 5 => ::core::result::Result::Ok(Category::Experimental), + 6 => ::core::result::Result::Ok(Category::Filesystem), + 7 => ::core::result::Result::Ok(Category::Filters), + 8 => ::core::result::Result::Ok(Category::Formats), + 9 => ::core::result::Result::Ok(Category::Math), + 10 => ::core::result::Result::Ok(Category::Strings), + 11 => ::core::result::Result::Ok(Category::System), + 12 => ::core::result::Result::Ok(Category::Viewers), + n => ::core::result::Result::Err(::capnp::NotInSchema(n)), + } + } +} +impl ::capnp::traits::ToU16 for Category { + #[inline] + fn to_u16(self) -> u16 { + self as u16 + } +} +impl ::capnp::traits::HasTypeId for Category { + #[inline] + fn type_id() -> u64 { + 0x8920_14c1_76ba_5343u64 + } +} + pub mod flag { #[derive(Copy, Clone)] pub struct Owned(()); diff --git a/crates/nu-plugin/src/serializers/signature.rs b/crates/nu-plugin/src/serializers/signature.rs index 4aaf9ea36..e54c1ec39 100644 --- a/crates/nu-plugin/src/serializers/signature.rs +++ b/crates/nu-plugin/src/serializers/signature.rs @@ -1,6 +1,6 @@ use crate::plugin::PluginError; -use crate::plugin_capnp::{argument, flag, signature, Shape}; -use nu_protocol::{Flag, PositionalArg, Signature, SyntaxShape}; +use crate::plugin_capnp::{argument, flag, signature, Category as PluginCategory, Shape}; +use nu_protocol::{Category, Flag, PositionalArg, Signature, SyntaxShape}; pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature::Builder) { builder.set_name(signature.name.as_str()); @@ -8,6 +8,22 @@ pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature: builder.set_extra_usage(signature.extra_usage.as_str()); builder.set_is_filter(signature.is_filter); + match signature.category { + Category::Default => builder.set_category(PluginCategory::Default), + Category::Conversions => builder.set_category(PluginCategory::Conversions), + Category::Core => builder.set_category(PluginCategory::Core), + Category::Date => builder.set_category(PluginCategory::Date), + Category::Env => builder.set_category(PluginCategory::Env), + Category::Experimental => builder.set_category(PluginCategory::Experimental), + Category::FileSystem => builder.set_category(PluginCategory::Filesystem), + Category::Filters => builder.set_category(PluginCategory::Filters), + Category::Formats => builder.set_category(PluginCategory::Formats), + Category::Math => builder.set_category(PluginCategory::Math), + Category::Strings => builder.set_category(PluginCategory::Strings), + Category::System => builder.set_category(PluginCategory::System), + Category::Viewers => builder.set_category(PluginCategory::Viewers), + } + // Serializing list of required arguments let mut required_list = builder .reborrow() @@ -90,6 +106,25 @@ pub(crate) fn deserialize_signature(reader: signature::Reader) -> Result Category::Default, + PluginCategory::Conversions => Category::Conversions, + PluginCategory::Core => Category::Core, + PluginCategory::Date => Category::Date, + PluginCategory::Env => Category::Env, + PluginCategory::Experimental => Category::Experimental, + PluginCategory::Filesystem => Category::FileSystem, + PluginCategory::Filters => Category::Filters, + PluginCategory::Formats => Category::Formats, + PluginCategory::Math => Category::Math, + PluginCategory::Strings => Category::Strings, + PluginCategory::System => Category::System, + PluginCategory::Viewers => Category::Viewers, + }; + // Deserializing required arguments let required_list = reader .get_required_positional() @@ -141,6 +176,7 @@ pub(crate) fn deserialize_signature(reader: signature::Reader) -> Result Result { mod tests { use super::*; use capnp::serialize; - use nu_protocol::{Signature, SyntaxShape}; + use nu_protocol::{Category, Signature, SyntaxShape}; pub fn write_buffer( signature: &Signature, @@ -262,7 +298,8 @@ mod tests { Some('s'), ) .switch("switch", "some switch", None) - .rest("remaining", SyntaxShape::Int, "remaining"); + .rest("remaining", SyntaxShape::Int, "remaining") + .category(Category::Conversions); let mut buffer: Vec = Vec::new(); write_buffer(&signature, &mut buffer).expect("unable to serialize message"); @@ -273,6 +310,7 @@ mod tests { assert_eq!(signature.usage, returned_signature.usage); assert_eq!(signature.extra_usage, returned_signature.extra_usage); assert_eq!(signature.is_filter, returned_signature.is_filter); + assert_eq!(signature.category, returned_signature.category); signature .required_positional diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index caeda6636..43d3491f5 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -27,6 +27,45 @@ pub struct PositionalArg { pub var_id: Option, } +#[derive(Debug, Clone, PartialEq)] +pub enum Category { + Default, + Conversions, + Core, + Date, + Env, + Experimental, + FileSystem, + Filters, + Formats, + Math, + Strings, + System, + Viewers, +} + +impl std::fmt::Display for Category { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let msg = match self { + Category::Default => "default", + Category::Conversions => "conversions", + Category::Core => "core", + Category::Date => "date", + Category::Env => "env", + Category::Experimental => "experimental", + Category::FileSystem => "filesystem", + Category::Filters => "filters", + Category::Formats => "formats", + Category::Math => "math", + Category::Strings => "strings", + Category::System => "system", + Category::Viewers => "viewers", + }; + + write!(f, "{}", msg) + } +} + #[derive(Clone, Debug)] pub struct Signature { pub name: String, @@ -38,6 +77,8 @@ pub struct Signature { pub named: Vec, pub is_filter: bool, pub creates_scope: bool, + // Signature category used to classify commands stored in the list of declarations + pub category: Category, } impl PartialEq for Signature { @@ -75,6 +116,7 @@ impl Signature { named: vec![flag], is_filter: false, creates_scope: false, + category: Category::Default, } } pub fn build(name: impl Into) -> Signature { @@ -202,6 +244,13 @@ impl Signature { self } + /// Changes the signature category + pub fn category(mut self, category: Category) -> Signature { + self.category = category; + + self + } + /// Sets that signature will create a scope as it parses pub fn creates_scope(mut self) -> Signature { self.creates_scope = true;