From bb6335830a92ac95ff825e96872e880c9f138aaa Mon Sep 17 00:00:00 2001 From: Michael Angerman <1809991+stormasm@users.noreply.github.com> Date: Sun, 6 Aug 2023 21:03:23 -0700 Subject: [PATCH] Categorification: move Path commands out of the default category (#9937) Path commands were incorrectly located in the default category... This PR moves all of the *Path* commands into their own Category called *Path* --- crates/nu-command/src/path/basename.rs | 8 ++++---- crates/nu-command/src/path/dirname.rs | 5 +++-- crates/nu-command/src/path/exists.rs | 18 ++++++++++-------- crates/nu-command/src/path/expand.rs | 3 ++- crates/nu-command/src/path/join.rs | 5 +++-- crates/nu-command/src/path/parse.rs | 5 +++-- crates/nu-command/src/path/path_.rs | 6 ++++-- crates/nu-command/src/path/relative_to.rs | 5 +++-- crates/nu-command/src/path/split.rs | 18 ++++++++++-------- crates/nu-command/src/path/type.rs | 3 ++- crates/nu-protocol/src/signature.rs | 2 ++ 11 files changed, 46 insertions(+), 32 deletions(-) diff --git a/crates/nu-command/src/path/basename.rs b/crates/nu-command/src/path/basename.rs index 5ac44040b..562a3464c 100644 --- a/crates/nu-command/src/path/basename.rs +++ b/crates/nu-command/src/path/basename.rs @@ -1,15 +1,14 @@ use std::path::Path; +use super::PathSubcommandArguments; use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, - Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, + SyntaxShape, Type, Value, }; -use super::PathSubcommandArguments; - struct Arguments { replace: Option>, } @@ -39,6 +38,7 @@ impl Command for SubCommand { "Return original path with basename replaced by this string", Some('r'), ) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/dirname.rs b/crates/nu-command/src/path/dirname.rs index 2b2df8a13..95b2a8e82 100644 --- a/crates/nu-command/src/path/dirname.rs +++ b/crates/nu-command/src/path/dirname.rs @@ -4,8 +4,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, - Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, + SyntaxShape, Type, Value, }; use super::PathSubcommandArguments; @@ -46,6 +46,7 @@ impl Command for SubCommand { "Number of directories to walk up", Some('n'), ) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/exists.rs b/crates/nu-command/src/path/exists.rs index 765f847b6..d457cd51d 100644 --- a/crates/nu-command/src/path/exists.rs +++ b/crates/nu-command/src/path/exists.rs @@ -5,7 +5,7 @@ use nu_path::expand_path_with; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value, }; use super::PathSubcommandArguments; @@ -25,13 +25,15 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("path exists").input_output_types(vec![ - (Type::String, Type::Bool), - ( - Type::List(Box::new(Type::String)), - Type::List(Box::new(Type::Bool)), - ), - ]) + Signature::build("path exists") + .input_output_types(vec![ + (Type::String, Type::Bool), + ( + Type::List(Box::new(Type::String)), + Type::List(Box::new(Type::Bool)), + ), + ]) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/expand.rs b/crates/nu-command/src/path/expand.rs index f64ac582c..99e72e3d5 100644 --- a/crates/nu-command/src/path/expand.rs +++ b/crates/nu-command/src/path/expand.rs @@ -5,7 +5,7 @@ use nu_path::{canonicalize_with, expand_path_with}; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value, }; use super::PathSubcommandArguments; @@ -41,6 +41,7 @@ impl Command for SubCommand { Some('s'), ) .switch("no-symlink", "Do not resolve symbolic links", Some('n')) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/join.rs b/crates/nu-command/src/path/join.rs index 1000760db..44a3a4ac5 100644 --- a/crates/nu-command/src/path/join.rs +++ b/crates/nu-command/src/path/join.rs @@ -5,8 +5,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, - Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, + SyntaxShape, Type, Value, }; use super::PathSubcommandArguments; @@ -34,6 +34,7 @@ impl Command for SubCommand { (Type::Table(vec![]), Type::List(Box::new(Type::String))), ]) .rest("append", SyntaxShape::String, "Path to append to the input") + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/parse.rs b/crates/nu-command/src/path/parse.rs index 66ef503c5..d8972e19c 100644 --- a/crates/nu-command/src/path/parse.rs +++ b/crates/nu-command/src/path/parse.rs @@ -5,8 +5,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, - Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, + SyntaxShape, Type, Value, }; use super::PathSubcommandArguments; @@ -37,6 +37,7 @@ impl Command for SubCommand { "Manually supply the extension (without the dot)", Some('e'), ) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/path_.rs b/crates/nu-command/src/path/path_.rs index 97c8b5197..4c1a2dc52 100644 --- a/crates/nu-command/src/path/path_.rs +++ b/crates/nu-command/src/path/path_.rs @@ -2,7 +2,7 @@ use nu_engine::get_full_help; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, - IntoPipelineData, PipelineData, ShellError, Signature, Type, Value, + Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value, }; #[derive(Clone)] @@ -14,7 +14,9 @@ impl Command for PathCommand { } fn signature(&self) -> Signature { - Signature::build("path").input_output_types(vec![(Type::Nothing, Type::String)]) + Signature::build("path") + .input_output_types(vec![(Type::Nothing, Type::String)]) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/relative_to.rs b/crates/nu-command/src/path/relative_to.rs index f56e86c1a..5b12986f0 100644 --- a/crates/nu-command/src/path/relative_to.rs +++ b/crates/nu-command/src/path/relative_to.rs @@ -5,8 +5,8 @@ use nu_path::expand_to_real_path; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, - Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, + SyntaxShape, Type, Value, }; use super::PathSubcommandArguments; @@ -39,6 +39,7 @@ impl Command for SubCommand { SyntaxShape::String, "Parent shared with the input path", ) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/split.rs b/crates/nu-command/src/path/split.rs index bbce5baeb..ab70d4966 100644 --- a/crates/nu-command/src/path/split.rs +++ b/crates/nu-command/src/path/split.rs @@ -3,7 +3,7 @@ use std::path::{Component, Path}; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value, }; use super::PathSubcommandArguments; @@ -21,13 +21,15 @@ impl Command for SubCommand { } fn signature(&self) -> Signature { - Signature::build("path split").input_output_types(vec![ - (Type::String, Type::List(Box::new(Type::String))), - ( - Type::List(Box::new(Type::String)), - Type::List(Box::new(Type::List(Box::new(Type::String)))), - ), - ]) + Signature::build("path split") + .input_output_types(vec![ + (Type::String, Type::List(Box::new(Type::String))), + ( + Type::List(Box::new(Type::String)), + Type::List(Box::new(Type::List(Box::new(Type::String)))), + ), + ]) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/path/type.rs b/crates/nu-command/src/path/type.rs index 665ae8296..2660cbf2f 100644 --- a/crates/nu-command/src/path/type.rs +++ b/crates/nu-command/src/path/type.rs @@ -4,7 +4,7 @@ use nu_path::expand_tilde; use nu_protocol::ast::Call; use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::{ - engine::Command, Example, PipelineData, ShellError, Signature, Span, Type, Value, + engine::Command, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value, }; use super::PathSubcommandArguments; @@ -31,6 +31,7 @@ impl Command for SubCommand { ), ]) .allow_variants_without_examples(true) + .category(Category::Path) } fn usage(&self) -> &str { diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index ad2b65f7f..8b453d7d7 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -60,6 +60,7 @@ pub enum Category { Math, Misc, Network, + Path, Platform, Random, Shells, @@ -91,6 +92,7 @@ impl std::fmt::Display for Category { Category::Math => "math", Category::Misc => "misc", Category::Network => "network", + Category::Path => "path", Category::Platform => "platform", Category::Random => "random", Category::Shells => "shells",