diff --git a/crates/nu-parser/src/hir/baseline_parse/tests.rs b/crates/nu-parser/src/hir/baseline_parse/tests.rs index 06bd0de328..2ace9e19bb 100644 --- a/crates/nu-parser/src/hir/baseline_parse/tests.rs +++ b/crates/nu-parser/src/hir/baseline_parse/tests.rs @@ -183,7 +183,11 @@ fn with_empty_context(source: &Text, callback: impl FnOnce(ExpandContext)) { SyntaxShape::Pattern, "a path to get the directory contents from", ) - .switch("full", "list all available columns for each entry"), + .switch( + "full", + "list all available columns for each entry", + Some('f'), + ), ); callback(ExpandContext::new(Box::new(registry), source, None)) diff --git a/crates/nu-parser/src/parse/token_tree.rs b/crates/nu-parser/src/parse/token_tree.rs index 7166629f87..ba3c502540 100644 --- a/crates/nu-parser/src/parse/token_tree.rs +++ b/crates/nu-parser/src/parse/token_tree.rs @@ -361,9 +361,20 @@ impl SpannedToken { } } - pub(crate) fn as_flag(&self, value: &str, source: &Text) -> Option { + pub(crate) fn as_flag(&self, value: &str, short: Option, source: &Text) -> Option { match self.unspanned() { - Token::Flag(flag @ Flag { .. }) if value == flag.name().slice(source) => Some(*flag), + Token::Flag(flag @ Flag { .. }) => { + let name = flag.name().slice(source); + let is_long = flag.kind == FlagKind::Longhand && value == name; + let is_short = flag.kind == FlagKind::Shorthand + && short.is_some() + && short == name.chars().nth(0); + if is_long || is_short { + Some(*flag) + } else { + None + } + } _ => None, } } diff --git a/crates/nu-parser/src/parse_command.rs b/crates/nu-parser/src/parse_command.rs index 47edbf2664..2a2ee1b58a 100644 --- a/crates/nu-parser/src/parse_command.rs +++ b/crates/nu-parser/src/parse_command.rs @@ -31,8 +31,8 @@ pub fn parse_command_tail( trace!(target: "nu::parse::trace_remaining", "looking for {} : {:?}", name, kind); match &kind.0 { - NamedType::Switch => { - let switch = extract_switch(name, tail); + NamedType::Switch(s) => { + let switch = extract_switch(name, *s, tail); match switch { None => named.insert_switch(name, None), @@ -45,8 +45,8 @@ pub fn parse_command_tail( } } } - NamedType::Mandatory(syntax_type) => { - match extract_mandatory(config, name, tail, command_span) { + NamedType::Mandatory(s, syntax_type) => { + match extract_mandatory(config, name, *s, tail, command_span) { Err(err) => { // remember this error, but continue coloring found_error = Some(err); @@ -71,8 +71,8 @@ pub fn parse_command_tail( } } } - NamedType::Optional(syntax_type) => { - match extract_optional(name, tail) { + NamedType::Optional(s, syntax_type) => { + match extract_optional(name, *s, tail) { Err(err) => { // remember this error, but continue coloring found_error = Some(err); @@ -270,10 +270,14 @@ fn expand_spaced_expr< fn extract_switch( name: &str, + short: Option, tokens: &mut hir::TokensIterator<'_>, ) -> Option<(usize, Spanned)> { let source = tokens.source(); - let switch = tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span()))); + let switch = tokens.extract(|t| { + t.as_flag(name, short, &source) + .map(|flag| flag.spanned(t.span())) + }); match switch { None => None, @@ -287,11 +291,15 @@ fn extract_switch( fn extract_mandatory( config: &Signature, name: &str, + short: Option, tokens: &mut hir::TokensIterator<'_>, span: Span, ) -> Result<(usize, Spanned), ParseError> { let source = tokens.source(); - let flag = tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span()))); + let flag = tokens.extract(|t| { + t.as_flag(name, short, &source) + .map(|flag| flag.spanned(t.span())) + }); match flag { None => Err(ParseError::argument_error( @@ -308,10 +316,14 @@ fn extract_mandatory( fn extract_optional( name: &str, + short: Option, tokens: &mut hir::TokensIterator<'_>, ) -> Result)>, ParseError> { let source = tokens.source(); - let flag = tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span()))); + let flag = tokens.extract(|t| { + t.as_flag(name, short, &source) + .map(|flag| flag.spanned(t.span())) + }); match flag { None => Ok(None), diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index 5697632879..7efe43583f 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -7,18 +7,28 @@ use serde::{Deserialize, Serialize}; /// The types of named parameter that a command can have #[derive(Debug, Serialize, Deserialize, Clone)] pub enum NamedType { - /// A flag without any associated argument. eg) `foo --bar` - Switch, - /// A mandatory flag, with associated argument. eg) `foo --required xyz` - Mandatory(SyntaxShape), - /// An optional flag, with associated argument. eg) `foo --optional abc` - Optional(SyntaxShape), + /// A flag without any associated argument. eg) `foo --bar, foo -b` + Switch(Option), + /// A mandatory flag, with associated argument. eg) `foo --required xyz, foo -r xyz` + Mandatory(Option, SyntaxShape), + /// An optional flag, with associated argument. eg) `foo --optional abc, foo -o abc` + Optional(Option, SyntaxShape), +} + +impl NamedType { + pub fn get_short(&self) -> Option { + match self { + NamedType::Switch(s) => *s, + NamedType::Mandatory(s, _) => *s, + NamedType::Optional(s, _) => *s, + } + } } /// The type of positional arguments #[derive(Debug, Clone, Serialize, Deserialize)] pub enum PositionalType { - /// A mandatory postional argument with the expected shape of the value + /// A mandatory positional argument with the expected shape of the value Mandatory(String, SyntaxShape), /// An optional positional argument with the expected shape of the value Optional(String, SyntaxShape), @@ -120,7 +130,10 @@ impl Signature { pub fn allowed(&self) -> Vec { let mut allowed = indexmap::IndexSet::new(); - for (name, _) in &self.named { + for (name, (t, _)) in &self.named { + if let Some(c) = t.get_short() { + allowed.insert(format!("-{}", c)); + } allowed.insert(format!("--{}", name)); } @@ -157,14 +170,14 @@ impl PrettyDebugWithSource for Signature { } impl Signature { - /// Create a new command signagure with the given name + /// Create a new command signature with the given name pub fn new(name: impl Into) -> Signature { Signature { name: name.into(), usage: String::new(), positional: vec![], rest_positional: None, - named: indexmap::indexmap! {"help".into() => (NamedType::Switch, "Display this help message".into())}, + named: indexmap::indexmap! {"help".into() => (NamedType::Switch(Some('h')), "Display this help message".into())}, is_filter: false, yields: None, input: None, @@ -218,9 +231,16 @@ impl Signature { name: impl Into, ty: impl Into, desc: impl Into, + short: Option, ) -> Signature { - self.named - .insert(name.into(), (NamedType::Optional(ty.into()), desc.into())); + let s = short.and_then(|c| { + debug_assert!(!self.get_shorts().contains(&c)); + Some(c) + }); + self.named.insert( + name.into(), + (NamedType::Optional(s, ty.into()), desc.into()), + ); self } @@ -231,17 +251,35 @@ impl Signature { name: impl Into, ty: impl Into, desc: impl Into, + short: Option, ) -> Signature { - self.named - .insert(name.into(), (NamedType::Mandatory(ty.into()), desc.into())); + let s = short.and_then(|c| { + debug_assert!(!self.get_shorts().contains(&c)); + Some(c) + }); + + self.named.insert( + name.into(), + (NamedType::Mandatory(s, ty.into()), desc.into()), + ); self } /// Add a switch to the signature - pub fn switch(mut self, name: impl Into, desc: impl Into) -> Signature { + pub fn switch( + mut self, + name: impl Into, + desc: impl Into, + short: Option, + ) -> Signature { + let s = short.and_then(|c| { + debug_assert!(!self.get_shorts().contains(&c)); + Some(c) + }); + self.named - .insert(name.into(), (NamedType::Switch, desc.into())); + .insert(name.into(), (NamedType::Switch(s), desc.into())); self } @@ -268,4 +306,15 @@ impl Signature { self.input = Some(ty); self } + + /// Get list of the short-hand flags + pub fn get_shorts(&self) -> Vec { + let mut shorts = Vec::new(); + for (_, (t, _)) in &self.named { + if let Some(c) = t.get_short() { + shorts.push(c); + } + } + shorts + } } diff --git a/crates/nu_plugin_binaryview/src/nu/mod.rs b/crates/nu_plugin_binaryview/src/nu/mod.rs index 01a119eb6e..091cc0c257 100644 --- a/crates/nu_plugin_binaryview/src/nu/mod.rs +++ b/crates/nu_plugin_binaryview/src/nu/mod.rs @@ -9,7 +9,7 @@ impl Plugin for BinaryView { fn config(&mut self) -> Result { Ok(Signature::build("binaryview") .desc("Autoview of binary data.") - .switch("lores", "use low resolution output mode")) + .switch("lores", "use low resolution output mode", Some('l'))) } fn sink(&mut self, call_info: CallInfo, input: Vec) { diff --git a/crates/nu_plugin_fetch/src/nu/mod.rs b/crates/nu_plugin_fetch/src/nu/mod.rs index a4ae3b55c2..55857a79be 100644 --- a/crates/nu_plugin_fetch/src/nu/mod.rs +++ b/crates/nu_plugin_fetch/src/nu/mod.rs @@ -15,7 +15,7 @@ impl Plugin for Fetch { SyntaxShape::Path, "the URL to fetch the contents from", ) - .switch("raw", "fetch contents as text rather than a table") + .switch("raw", "fetch contents as text rather than a table", Some('r')) .filter()) } diff --git a/crates/nu_plugin_inc/src/nu/mod.rs b/crates/nu_plugin_inc/src/nu/mod.rs index 64622374b6..f3b8c5eb6b 100644 --- a/crates/nu_plugin_inc/src/nu/mod.rs +++ b/crates/nu_plugin_inc/src/nu/mod.rs @@ -16,9 +16,21 @@ impl Plugin for Inc { fn config(&mut self) -> Result { Ok(Signature::build("inc") .desc("Increment a value or version. Optionally use the column of a table.") - .switch("major", "increment the major version (eg 1.2.1 -> 2.0.0)") - .switch("minor", "increment the minor version (eg 1.2.1 -> 1.3.0)") - .switch("patch", "increment the patch version (eg 1.2.1 -> 1.2.2)") + .switch( + "major", + "increment the major version (eg 1.2.1 -> 2.0.0)", + Some('M'), + ) + .switch( + "minor", + "increment the minor version (eg 1.2.1 -> 1.3.0)", + Some('m'), + ) + .switch( + "patch", + "increment the patch version (eg 1.2.1 -> 1.2.2)", + Some('p'), + ) .rest(SyntaxShape::ColumnPath, "the column(s) to update") .filter()) } diff --git a/crates/nu_plugin_post/src/nu/mod.rs b/crates/nu_plugin_post/src/nu/mod.rs index 7318f060b4..20dbda0cdd 100644 --- a/crates/nu_plugin_post/src/nu/mod.rs +++ b/crates/nu_plugin_post/src/nu/mod.rs @@ -12,23 +12,35 @@ impl Plugin for Post { .desc("Post content to a url and retrieve data as a table if possible.") .required("path", SyntaxShape::Any, "the URL to post to") .required("body", SyntaxShape::Any, "the contents of the post body") - .named("user", SyntaxShape::Any, "the username when authenticating") + .named( + "user", + SyntaxShape::Any, + "the username when authenticating", + Some('u'), + ) .named( "password", SyntaxShape::Any, "the password when authenticating", + Some('p'), ) .named( "content-type", SyntaxShape::Any, "the MIME type of content to post", + Some('t'), ) .named( "content-length", SyntaxShape::Any, "the length of the content being posted", + Some('l'), + ) + .switch( + "raw", + "return values as a string instead of a table", + Some('r'), ) - .switch("raw", "return values as a string instead of a table") .filter()) } diff --git a/crates/nu_plugin_str/src/nu/mod.rs b/crates/nu_plugin_str/src/nu/mod.rs index bbde92604b..c74c821458 100644 --- a/crates/nu_plugin_str/src/nu/mod.rs +++ b/crates/nu_plugin_str/src/nu/mod.rs @@ -15,19 +15,26 @@ impl Plugin for Str { fn config(&mut self) -> Result { Ok(Signature::build("str") .desc("Apply string function. Optional use the column of a table") - .switch("downcase", "convert string to lowercase") - .switch("upcase", "convert string to uppercase") - .switch("to-int", "convert string to integer") - .named("replace", SyntaxShape::String, "replaces the string") + .switch("downcase", "convert string to lowercase", Some('d')) + .switch("upcase", "convert string to uppercase", Some('U')) + .switch("to-int", "convert string to integer", Some('i')) + .named( + "replace", + SyntaxShape::String, + "replaces the string", + Some('r'), + ) .named( "find-replace", SyntaxShape::Any, "finds and replaces [pattern replacement]", + Some('f'), ) .named( "substring", SyntaxShape::String, "convert string to portion of original, requires \"start,end\"", + Some('s'), ) .rest(SyntaxShape::ColumnPath, "the column(s) to convert") .filter()) diff --git a/src/commands/config.rs b/src/commands/config.rs index dd9244b41a..59ce1ed44b 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -31,21 +31,34 @@ impl WholeStreamCommand for Config { "load", SyntaxShape::Path, "load the config from the path give", + Some('l'), ) .named( "set", SyntaxShape::Any, "set a value in the config, eg) --set [key value]", + Some('s'), ) .named( "set_into", SyntaxShape::Member, "sets a variable from values in the pipeline", + Some('i'), ) - .named("get", SyntaxShape::Any, "get a value from the config") - .named("remove", SyntaxShape::Any, "remove a value from the config") - .switch("clear", "clear the config") - .switch("path", "return the path to the config file") + .named( + "get", + SyntaxShape::Any, + "get a value from the config", + Some('g'), + ) + .named( + "remove", + SyntaxShape::Any, + "remove a value from the config", + Some('r'), + ) + .switch("clear", "clear the config", Some('c')) + .switch("path", "return the path to the config file", Some('p')) } fn usage(&self) -> &str { diff --git a/src/commands/cp.rs b/src/commands/cp.rs index 58457431a6..1bd04040d4 100644 --- a/src/commands/cp.rs +++ b/src/commands/cp.rs @@ -24,7 +24,11 @@ impl PerItemCommand for Cpy { Signature::build("cp") .required("src", SyntaxShape::Pattern, "the place to copy from") .required("dst", SyntaxShape::Path, "the place to copy to") - .switch("recursive", "copy recursively through subdirectories") + .switch( + "recursive", + "copy recursively through subdirectories", + Some('r'), + ) } fn usage(&self) -> &str { diff --git a/src/commands/date.rs b/src/commands/date.rs index b559821fa2..45b730bd5c 100644 --- a/src/commands/date.rs +++ b/src/commands/date.rs @@ -18,8 +18,8 @@ impl WholeStreamCommand for Date { fn signature(&self) -> Signature { Signature::build("date") - .switch("utc", "use universal time (UTC)") - .switch("local", "use the local time") + .switch("utc", "use universal time (UTC)", Some('u')) + .switch("local", "use the local time", Some('l')) } fn usage(&self) -> &str { diff --git a/src/commands/debug.rs b/src/commands/debug.rs index a783d81767..63e09c3f91 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -16,7 +16,7 @@ impl WholeStreamCommand for Debug { } fn signature(&self) -> Signature { - Signature::build("debug").switch("raw", "Prints the raw value representation.") + Signature::build("debug").switch("raw", "Prints the raw value representation.", Some('r')) } fn usage(&self) -> &str { diff --git a/src/commands/du.rs b/src/commands/du.rs index ecd08edfa6..2b1c39e4fc 100644 --- a/src/commands/du.rs +++ b/src/commands/du.rs @@ -40,14 +40,33 @@ impl PerItemCommand for Du { fn signature(&self) -> Signature { Signature::build(NAME) .optional("path", SyntaxShape::Pattern, "starting directory") - .switch("all", "Output File sizes as well as directory sizes") - .switch("deref", "Dereference symlinks to their targets for size") - .named("exclude", SyntaxShape::Pattern, "Exclude these file names") - .named("max-depth", SyntaxShape::Int, "Directory recursion limit") + .switch( + "all", + "Output File sizes as well as directory sizes", + Some('a'), + ) + .switch( + "deref", + "Dereference symlinks to their targets for size", + Some('r'), + ) + .named( + "exclude", + SyntaxShape::Pattern, + "Exclude these file names", + Some('x'), + ) + .named( + "max-depth", + SyntaxShape::Int, + "Directory recursion limit", + Some('d'), + ) .named( "min-size", SyntaxShape::Int, "Exclude files below this size", + Some('m'), ) } diff --git a/src/commands/evaluate_by.rs b/src/commands/evaluate_by.rs index 81831cd1c3..b8969ee230 100644 --- a/src/commands/evaluate_by.rs +++ b/src/commands/evaluate_by.rs @@ -23,6 +23,7 @@ impl WholeStreamCommand for EvaluateBy { "evaluate_with", SyntaxShape::String, "the name of the column to evaluate by", + Some('w'), ) } diff --git a/src/commands/exit.rs b/src/commands/exit.rs index fc22502ebc..a775116777 100644 --- a/src/commands/exit.rs +++ b/src/commands/exit.rs @@ -12,7 +12,7 @@ impl WholeStreamCommand for Exit { } fn signature(&self) -> Signature { - Signature::build("exit").switch("now", "exit out of the shell immediately") + Signature::build("exit").switch("now", "exit out of the shell immediately", Some('n')) } fn usage(&self) -> &str { diff --git a/src/commands/from_csv.rs b/src/commands/from_csv.rs index fb821d7363..80439b9178 100644 --- a/src/commands/from_csv.rs +++ b/src/commands/from_csv.rs @@ -23,8 +23,13 @@ impl WholeStreamCommand for FromCSV { "separator", SyntaxShape::String, "a character to separate columns, defaults to ','", + Some('s'), + ) + .switch( + "headerless", + "don't treat the first row as column names", + None, ) - .switch("headerless", "don't treat the first row as column names") } fn usage(&self) -> &str { diff --git a/src/commands/from_json.rs b/src/commands/from_json.rs index ea06d1ebf3..75e9d0b3e3 100644 --- a/src/commands/from_json.rs +++ b/src/commands/from_json.rs @@ -16,7 +16,11 @@ impl WholeStreamCommand for FromJSON { } fn signature(&self) -> Signature { - Signature::build("from-json").switch("objects", "treat each line as a separate value") + Signature::build("from-json").switch( + "objects", + "treat each line as a separate value", + Some('o'), + ) } fn usage(&self) -> &str { diff --git a/src/commands/from_ods.rs b/src/commands/from_ods.rs index 0f1910250f..118a86b7c9 100644 --- a/src/commands/from_ods.rs +++ b/src/commands/from_ods.rs @@ -19,8 +19,11 @@ impl WholeStreamCommand for FromODS { } fn signature(&self) -> Signature { - Signature::build("from-ods") - .switch("headerless", "don't treat the first row as column names") + Signature::build("from-ods").switch( + "headerless", + "don't treat the first row as column names", + None, + ) } fn usage(&self) -> &str { diff --git a/src/commands/from_ssv.rs b/src/commands/from_ssv.rs index 7b8d870203..a29b12a9ad 100644 --- a/src/commands/from_ssv.rs +++ b/src/commands/from_ssv.rs @@ -27,12 +27,17 @@ impl WholeStreamCommand for FromSSV { fn signature(&self) -> Signature { Signature::build(STRING_REPRESENTATION) - .switch("headerless", "don't treat the first row as column names") - .switch("aligned-columns", "assume columns are aligned") + .switch( + "headerless", + "don't treat the first row as column names", + None, + ) + .switch("aligned-columns", "assume columns are aligned", Some('a')) .named( "minimum-spaces", SyntaxShape::Int, - "the mininum spaces to separate columns", + "the minimum spaces to separate columns", + Some('m'), ) } diff --git a/src/commands/from_tsv.rs b/src/commands/from_tsv.rs index c4807dd912..425bf302dd 100644 --- a/src/commands/from_tsv.rs +++ b/src/commands/from_tsv.rs @@ -17,8 +17,11 @@ impl WholeStreamCommand for FromTSV { } fn signature(&self) -> Signature { - Signature::build("from-tsv") - .switch("headerless", "don't treat the first row as column names") + Signature::build("from-tsv").switch( + "headerless", + "don't treat the first row as column names", + None, + ) } fn usage(&self) -> &str { diff --git a/src/commands/from_xlsx.rs b/src/commands/from_xlsx.rs index 3a86a50f1f..5394efb0ea 100644 --- a/src/commands/from_xlsx.rs +++ b/src/commands/from_xlsx.rs @@ -19,8 +19,11 @@ impl WholeStreamCommand for FromXLSX { } fn signature(&self) -> Signature { - Signature::build("from-xlsx") - .switch("headerless", "don't treat the first row as column names") + Signature::build("from-xlsx").switch( + "headerless", + "don't treat the first row as column names", + None, + ) } fn usage(&self) -> &str { diff --git a/src/commands/help.rs b/src/commands/help.rs index 3594339dd9..9448e5bd5c 100644 --- a/src/commands/help.rs +++ b/src/commands/help.rs @@ -171,34 +171,67 @@ pub(crate) fn get_help( if !signature.named.is_empty() { long_desc.push_str("\nflags:\n"); for (flag, ty) in signature.named { - match ty.0 { - NamedType::Switch => { - long_desc.push_str(&format!( - " --{}{} {}\n", - flag, - if !ty.1.is_empty() { ":" } else { "" }, - ty.1 - )); + let msg = match ty.0 { + NamedType::Switch(s) => { + if let Some(c) = s { + format!( + " -{}, --{}{} {}\n", + c, + flag, + if !ty.1.is_empty() { ":" } else { "" }, + ty.1 + ) + } else { + format!( + " --{}{} {}\n", + flag, + if !ty.1.is_empty() { ":" } else { "" }, + ty.1 + ) + } } - NamedType::Mandatory(m) => { - long_desc.push_str(&format!( - " --{} <{}> (required parameter){} {}\n", - flag, - m.display(), - if !ty.1.is_empty() { ":" } else { "" }, - ty.1 - )); + NamedType::Mandatory(s, m) => { + if let Some(c) = s { + format!( + " -{}, --{} <{}> (required parameter){} {}\n", + c, + flag, + m.display(), + if !ty.1.is_empty() { ":" } else { "" }, + ty.1 + ) + } else { + format!( + " --{} <{}> (required parameter){} {}\n", + flag, + m.display(), + if !ty.1.is_empty() { ":" } else { "" }, + ty.1 + ) + } } - NamedType::Optional(o) => { - long_desc.push_str(&format!( - " --{} <{}>{} {}\n", - flag, - o.display(), - if !ty.1.is_empty() { ":" } else { "" }, - ty.1 - )); + NamedType::Optional(s, o) => { + if let Some(c) = s { + format!( + " -{}, --{} <{}>{} {}\n", + c, + flag, + o.display(), + if !ty.1.is_empty() { ":" } else { "" }, + ty.1 + ) + } else { + format!( + " --{} <{}>{} {}\n", + flag, + o.display(), + if !ty.1.is_empty() { ":" } else { "" }, + ty.1 + ) + } } - } + }; + long_desc.push_str(&msg); } } diff --git a/src/commands/kill.rs b/src/commands/kill.rs index c6aaed476d..cc11d60a16 100644 --- a/src/commands/kill.rs +++ b/src/commands/kill.rs @@ -29,8 +29,8 @@ impl PerItemCommand for Kill { "process id of process that is to be killed", ) .rest(SyntaxShape::Int, "rest of processes to kill") - .switch("force", "forcefully kill the process") - .switch("quiet", "won't print anything to the console") + .switch("force", "forcefully kill the process", Some('f')) + .switch("quiet", "won't print anything to the console", Some('q')) } fn usage(&self) -> &str { diff --git a/src/commands/ls.rs b/src/commands/ls.rs index 06c378f397..b2252bdf23 100644 --- a/src/commands/ls.rs +++ b/src/commands/ls.rs @@ -29,11 +29,20 @@ impl PerItemCommand for Ls { SyntaxShape::Pattern, "a path to get the directory contents from", ) - .switch("full", "list all available columns for each entry") - .switch("short-names", "only print the file names and not the path") + .switch( + "full", + "list all available columns for each entry", + Some('f'), + ) + .switch( + "short-names", + "only print the file names and not the path", + Some('s'), + ) .switch( "with-symlink-targets", "display the paths to the target files that symlinks point to", + Some('w'), ) } diff --git a/src/commands/map_max_by.rs b/src/commands/map_max_by.rs index 2f94fe32ef..d4b1e051f9 100644 --- a/src/commands/map_max_by.rs +++ b/src/commands/map_max_by.rs @@ -24,6 +24,7 @@ impl WholeStreamCommand for MapMaxBy { "column_name", SyntaxShape::String, "the name of the column to map-max the table's rows", + Some('c'), ) } diff --git a/src/commands/open.rs b/src/commands/open.rs index 91a5aa031e..d416a9c2ac 100644 --- a/src/commands/open.rs +++ b/src/commands/open.rs @@ -20,7 +20,11 @@ impl PerItemCommand for Open { SyntaxShape::Path, "the file path to load values from", ) - .switch("raw", "load content as a string insead of a table") + .switch( + "raw", + "load content as a string instead of a table", + Some('r'), + ) } fn usage(&self) -> &str { diff --git a/src/commands/pivot.rs b/src/commands/pivot.rs index 810b977200..55f8078e02 100644 --- a/src/commands/pivot.rs +++ b/src/commands/pivot.rs @@ -23,8 +23,16 @@ impl WholeStreamCommand for Pivot { fn signature(&self) -> Signature { Signature::build("pivot") - .switch("header-row", "treat the first row as column names") - .switch("ignore-titles", "don't pivot the column names into values") + .switch( + "header-row", + "treat the first row as column names", + Some('h'), + ) + .switch( + "ignore-titles", + "don't pivot the column names into values", + Some('i'), + ) .rest( SyntaxShape::String, "the names to give columns once pivoted", diff --git a/src/commands/reduce_by.rs b/src/commands/reduce_by.rs index c36a1bd2fa..7be7fb77e1 100644 --- a/src/commands/reduce_by.rs +++ b/src/commands/reduce_by.rs @@ -23,6 +23,7 @@ impl WholeStreamCommand for ReduceBy { "reduce_with", SyntaxShape::String, "the command to reduce by with", + Some('w'), ) } diff --git a/src/commands/rm.rs b/src/commands/rm.rs index dbc6de7faa..10a2c44e5e 100644 --- a/src/commands/rm.rs +++ b/src/commands/rm.rs @@ -26,8 +26,9 @@ impl PerItemCommand for Remove { .switch( "trash", "use the platform's recycle bin instead of permanently deleting", + Some('t'), ) - .switch("recursive", "delete subdirectories recursively") + .switch("recursive", "delete subdirectories recursively", Some('r')) } fn usage(&self) -> &str { diff --git a/src/commands/save.rs b/src/commands/save.rs index 1c1d06cae1..bb8aab4453 100644 --- a/src/commands/save.rs +++ b/src/commands/save.rs @@ -98,6 +98,7 @@ impl WholeStreamCommand for Save { .switch( "raw", "treat values as-is rather than auto-converting based on file extension", + Some('r'), ) } diff --git a/src/commands/split_by.rs b/src/commands/split_by.rs index 47f1588a48..94254163b6 100644 --- a/src/commands/split_by.rs +++ b/src/commands/split_by.rs @@ -27,7 +27,7 @@ impl WholeStreamCommand for SplitBy { } fn usage(&self) -> &str { - "Creates a new table with the data from the inner tables splitted by the column given." + "Creates a new table with the data from the inner tables split by the column given." } fn run( diff --git a/src/commands/split_column.rs b/src/commands/split_column.rs index 643c9323c1..1af02b1a4b 100644 --- a/src/commands/split_column.rs +++ b/src/commands/split_column.rs @@ -29,7 +29,7 @@ impl WholeStreamCommand for SplitColumn { SyntaxShape::Any, "the character that denotes what separates columns", ) - .switch("collapse-empty", "remove empty columns") + .switch("collapse-empty", "remove empty columns", Some('c')) .rest(SyntaxShape::Member, "column names to give the new columns") } diff --git a/src/commands/t_sort_by.rs b/src/commands/t_sort_by.rs index 93abe4f1a0..feaafeac76 100644 --- a/src/commands/t_sort_by.rs +++ b/src/commands/t_sort_by.rs @@ -28,16 +28,22 @@ impl WholeStreamCommand for TSortBy { fn signature(&self) -> Signature { Signature::build("t-sort-by") - .switch("show-columns", "Displays the column names sorted") + .switch( + "show-columns", + "Displays the column names sorted", + Some('c'), + ) .named( "group_by", SyntaxShape::String, "the name of the column to group by", + Some('g'), ) .named( "split_by", SyntaxShape::String, "the name of the column within the grouped by table to split by", + Some('s'), ) } diff --git a/src/commands/table.rs b/src/commands/table.rs index 1de2665a77..795879d95b 100644 --- a/src/commands/table.rs +++ b/src/commands/table.rs @@ -20,6 +20,7 @@ impl WholeStreamCommand for Table { "start_number", SyntaxShape::Number, "row number to start viewing from", + Some('n'), ) } diff --git a/src/commands/to_csv.rs b/src/commands/to_csv.rs index ca077a21a5..6806313265 100644 --- a/src/commands/to_csv.rs +++ b/src/commands/to_csv.rs @@ -21,6 +21,7 @@ impl WholeStreamCommand for ToCSV { Signature::build("to-csv").switch( "headerless", "do not output the columns names as the first row", + None, ) } diff --git a/src/commands/to_tsv.rs b/src/commands/to_tsv.rs index 3177e1dca9..2ab9c13529 100644 --- a/src/commands/to_tsv.rs +++ b/src/commands/to_tsv.rs @@ -20,6 +20,7 @@ impl WholeStreamCommand for ToTSV { Signature::build("to-tsv").switch( "headerless", "do not output the column names as the first row", + None, ) } diff --git a/src/commands/which_.rs b/src/commands/which_.rs index d13afe3181..a14a1c71ed 100644 --- a/src/commands/which_.rs +++ b/src/commands/which_.rs @@ -15,7 +15,7 @@ impl WholeStreamCommand for Which { fn signature(&self) -> Signature { Signature::build("which") .required("application", SyntaxShape::String, "application") - .switch("all", "list all executables") + .switch("all", "list all executables", Some('a')) } fn usage(&self) -> &str { diff --git a/src/data/command.rs b/src/data/command.rs index 91c52bc0e5..666008376f 100644 --- a/src/data/command.rs +++ b/src/data/command.rs @@ -60,9 +60,9 @@ fn signature_dict(signature: Signature, tag: impl Into) -> Value { for (name, ty) in signature.named.iter() { match ty.0 { - NamedType::Mandatory(_) => sig.push_value(for_spec(name, "flag", true, &tag)), - NamedType::Optional(_) => sig.push_value(for_spec(name, "flag", false, &tag)), - NamedType::Switch => sig.push_value(for_spec(name, "switch", false, &tag)), + NamedType::Mandatory(_, _) => sig.push_value(for_spec(name, "flag", true, &tag)), + NamedType::Optional(_, _) => sig.push_value(for_spec(name, "flag", false, &tag)), + NamedType::Switch(_) => sig.push_value(for_spec(name, "switch", false, &tag)), } } diff --git a/tests/commands/cp.rs b/tests/commands/cp.rs index 72516d4370..4c9362ab53 100644 --- a/tests/commands/cp.rs +++ b/tests/commands/cp.rs @@ -60,7 +60,7 @@ fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_r nu!( cwd: dirs.test(), - "cp originals expected --recursive" + "cp originals expected -r" ); assert!(expected_dir.exists()); diff --git a/tests/commands/lines.rs b/tests/commands/lines.rs index e11569e2a4..87e2f5c16a 100644 --- a/tests/commands/lines.rs +++ b/tests/commands/lines.rs @@ -5,7 +5,7 @@ fn lines() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" - open cargo_sample.toml --raw + open cargo_sample.toml -r | lines | skip-while $it != "[dependencies]" | skip 1 diff --git a/tests/commands/rm.rs b/tests/commands/rm.rs index 8cdb1e6283..caaee55e83 100644 --- a/tests/commands/rm.rs +++ b/tests/commands/rm.rs @@ -81,7 +81,7 @@ fn removes_deeply_nested_directories_with_wildcard_and_recursive_flag() { nu!( cwd: dirs.test(), - "rm --recursive src/*" + "rm -r src/*" ); assert!(!files_exist_at( diff --git a/tests/format_conversions/json.rs b/tests/format_conversions/json.rs index 5034347a07..9788afc123 100644 --- a/tests/format_conversions/json.rs +++ b/tests/format_conversions/json.rs @@ -61,7 +61,7 @@ fn from_json_text_recognizing_objects_independently_to_table() { cwd: dirs.test(), pipeline( r#" open katz.txt - | from-json --objects + | from-json -o | where name == "GorbyPuff" | get rusty_luck | echo $it diff --git a/tests/format_conversions/ssv.rs b/tests/format_conversions/ssv.rs index 18e0ad6f83..91854f3849 100644 --- a/tests/format_conversions/ssv.rs +++ b/tests/format_conversions/ssv.rs @@ -74,7 +74,7 @@ fn from_ssv_text_treating_first_line_as_data_with_flag() { cwd: dirs.test(), pipeline( r#" open oc_get_svc.txt - | from-ssv --headerless --aligned-columns + | from-ssv --headerless -a | first | get Column1 | echo $it diff --git a/tests/plugins/core_inc.rs b/tests/plugins/core_inc.rs index e77475a725..d90a7b4f4f 100644 --- a/tests/plugins/core_inc.rs +++ b/tests/plugins/core_inc.rs @@ -65,7 +65,7 @@ fn semversion_major_inc() { let actual = nu!( cwd: dirs.test(), - "open sample.toml | inc package.version --major | get package.version | echo $it" + "open sample.toml | inc package.version -M | get package.version | echo $it" ); assert_eq!(actual, "1.0.0"); diff --git a/tests/plugins/core_str.rs b/tests/plugins/core_str.rs index 3f61802af2..2908d452a9 100644 --- a/tests/plugins/core_str.rs +++ b/tests/plugins/core_str.rs @@ -46,7 +46,7 @@ fn downcases() { let actual = nu!( cwd: dirs.test(), - "open sample.toml | str dependency.name --downcase | get dependency.name | echo $it" + "open sample.toml | str dependency.name -d | get dependency.name | echo $it" ); assert_eq!(actual, "light");