diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 05d312b10..5d3abb40d 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -320,6 +320,7 @@ pub fn create_default_context( whole_stream_command(Histogram), whole_stream_command(Sum), // File format output + whole_stream_command(To), whole_stream_command(ToBSON), whole_stream_command(ToCSV), whole_stream_command(ToHTML), @@ -332,6 +333,7 @@ pub fn create_default_context( whole_stream_command(ToURL), whole_stream_command(ToYAML), // File format input + whole_stream_command(From), whole_stream_command(FromCSV), whole_stream_command(FromEML), whole_stream_command(FromTSV), diff --git a/crates/nu-cli/src/commands.rs b/crates/nu-cli/src/commands.rs index eabb5af3a..cd6f9f0ed 100644 --- a/crates/nu-cli/src/commands.rs +++ b/crates/nu-cli/src/commands.rs @@ -31,6 +31,7 @@ pub(crate) mod evaluate_by; pub(crate) mod exit; pub(crate) mod first; pub(crate) mod format; +pub(crate) mod from; pub(crate) mod from_bson; pub(crate) mod from_csv; pub(crate) mod from_eml; @@ -101,6 +102,7 @@ pub(crate) mod sum; pub(crate) mod t_sort_by; pub(crate) mod table; pub(crate) mod tags; +pub(crate) mod to; pub(crate) mod to_bson; pub(crate) mod to_csv; pub(crate) mod to_html; @@ -150,6 +152,7 @@ pub(crate) use evaluate_by::EvaluateBy; pub(crate) use exit::Exit; pub(crate) use first::First; pub(crate) use format::Format; +pub(crate) use from::From; pub(crate) use from_bson::FromBSON; pub(crate) use from_csv::FromCSV; pub(crate) use from_eml::FromEML; @@ -219,6 +222,7 @@ pub(crate) use sum::Sum; pub(crate) use t_sort_by::TSortBy; pub(crate) use table::Table; pub(crate) use tags::Tags; +pub(crate) use to::To; pub(crate) use to_bson::ToBSON; pub(crate) use to_csv::ToCSV; pub(crate) use to_html::ToHTML; diff --git a/crates/nu-cli/src/commands/classified/internal.rs b/crates/nu-cli/src/commands/classified/internal.rs index a22fd32cf..2ab83f772 100644 --- a/crates/nu-cli/src/commands/classified/internal.rs +++ b/crates/nu-cli/src/commands/classified/internal.rs @@ -51,7 +51,7 @@ pub(crate) fn run_internal_command( } CommandAction::AutoConvert(tagged_contents, extension) => { let contents_tag = tagged_contents.tag.clone(); - let command_name = format!("from-{}", extension); + let command_name = format!("from {}", extension); let command = command.clone(); if let Some(converter) = context.registry.get_command(&command_name) { let new_args = RawCommandArgs { diff --git a/crates/nu-cli/src/commands/command.rs b/crates/nu-cli/src/commands/command.rs index 48f4cba02..9f6a52b92 100644 --- a/crates/nu-cli/src/commands/command.rs +++ b/crates/nu-cli/src/commands/command.rs @@ -407,7 +407,7 @@ impl Command { pub fn run(&self, args: CommandArgs, registry: &CommandRegistry) -> OutputStream { if args.call_info.switch_present("help") { - get_help(self.name(), self.usage(), self.signature()).into() + get_help(self.name(), self.usage(), self.signature(), registry).into() } else { match self.0.run(args, registry) { Ok(stream) => stream, diff --git a/crates/nu-cli/src/commands/enter.rs b/crates/nu-cli/src/commands/enter.rs index d704ef2bc..66f7e4698 100644 --- a/crates/nu-cli/src/commands/enter.rs +++ b/crates/nu-cli/src/commands/enter.rs @@ -95,7 +95,7 @@ fn enter( let tagged_contents = contents.into_value(&contents_tag); if let Some(extension) = file_extension { - let command_name = format!("from-{}", extension); + let command_name = format!("from {}", extension); if let Some(converter) = registry.get_command(&command_name) { diff --git a/crates/nu-cli/src/commands/from.rs b/crates/nu-cli/src/commands/from.rs new file mode 100644 index 000000000..61dc92c9d --- /dev/null +++ b/crates/nu-cli/src/commands/from.rs @@ -0,0 +1,31 @@ +use crate::commands::WholeStreamCommand; +use crate::prelude::*; +use nu_errors::ShellError; +use nu_protocol::Signature; + +pub struct From; + +impl WholeStreamCommand for From { + fn name(&self) -> &str { + "from" + } + + fn signature(&self) -> Signature { + Signature::build("from") + } + + fn usage(&self) -> &str { + "Parse content (string or binary) as a table." + } + + fn run( + &self, + _args: CommandArgs, + registry: &CommandRegistry, + ) -> Result { + Ok( + crate::commands::help::get_help(self.name(), self.usage(), self.signature(), registry) + .into(), + ) + } +} diff --git a/crates/nu-cli/src/commands/from_bson.rs b/crates/nu-cli/src/commands/from_bson.rs index 92849e670..98a29bde5 100644 --- a/crates/nu-cli/src/commands/from_bson.rs +++ b/crates/nu-cli/src/commands/from_bson.rs @@ -10,15 +10,15 @@ pub struct FromBSON; impl WholeStreamCommand for FromBSON { fn name(&self) -> &str { - "from-bson" + "from bson" } fn signature(&self) -> Signature { - Signature::build("from-bson") + Signature::build("from bson") } fn usage(&self) -> &str { - "Parse text as .bson and create table." + "Parse binary as .bson and create table." } fn run( diff --git a/crates/nu-cli/src/commands/from_csv.rs b/crates/nu-cli/src/commands/from_csv.rs index 80439b917..81b3bf0af 100644 --- a/crates/nu-cli/src/commands/from_csv.rs +++ b/crates/nu-cli/src/commands/from_csv.rs @@ -14,11 +14,11 @@ pub struct FromCSVArgs { impl WholeStreamCommand for FromCSV { fn name(&self) -> &str { - "from-csv" + "from csv" } fn signature(&self) -> Signature { - Signature::build("from-csv") + Signature::build("from csv") .named( "separator", SyntaxShape::String, diff --git a/crates/nu-cli/src/commands/from_eml.rs b/crates/nu-cli/src/commands/from_eml.rs index cd9e62f24..251468954 100644 --- a/crates/nu-cli/src/commands/from_eml.rs +++ b/crates/nu-cli/src/commands/from_eml.rs @@ -18,11 +18,11 @@ pub struct FromEMLArgs { impl WholeStreamCommand for FromEML { fn name(&self) -> &str { - "from-eml" + "from eml" } fn signature(&self) -> Signature { - Signature::build("from-eml").named( + Signature::build("from eml").named( "preview-body", SyntaxShape::Int, "How many bytes of the body to preview", diff --git a/crates/nu-cli/src/commands/from_ics.rs b/crates/nu-cli/src/commands/from_ics.rs index 99e3f685e..79f3fcfb2 100644 --- a/crates/nu-cli/src/commands/from_ics.rs +++ b/crates/nu-cli/src/commands/from_ics.rs @@ -11,11 +11,11 @@ pub struct FromIcs; impl WholeStreamCommand for FromIcs { fn name(&self) -> &str { - "from-ics" + "from ics" } fn signature(&self) -> Signature { - Signature::build("from-ics") + Signature::build("from ics") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_ini.rs b/crates/nu-cli/src/commands/from_ini.rs index 98d85f386..f0cd5a1e5 100644 --- a/crates/nu-cli/src/commands/from_ini.rs +++ b/crates/nu-cli/src/commands/from_ini.rs @@ -8,11 +8,11 @@ pub struct FromINI; impl WholeStreamCommand for FromINI { fn name(&self) -> &str { - "from-ini" + "from ini" } fn signature(&self) -> Signature { - Signature::build("from-ini") + Signature::build("from ini") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_json.rs b/crates/nu-cli/src/commands/from_json.rs index 4b48dfe5d..be1b23f7e 100644 --- a/crates/nu-cli/src/commands/from_json.rs +++ b/crates/nu-cli/src/commands/from_json.rs @@ -12,11 +12,11 @@ pub struct FromJSONArgs { impl WholeStreamCommand for FromJSON { fn name(&self) -> &str { - "from-json" + "from json" } fn signature(&self) -> Signature { - Signature::build("from-json").switch( + Signature::build("from json").switch( "objects", "treat each line as a separate value", Some('o'), diff --git a/crates/nu-cli/src/commands/from_ods.rs b/crates/nu-cli/src/commands/from_ods.rs index 0992ee1e7..a429bce2e 100644 --- a/crates/nu-cli/src/commands/from_ods.rs +++ b/crates/nu-cli/src/commands/from_ods.rs @@ -15,11 +15,11 @@ pub struct FromODSArgs { impl WholeStreamCommand for FromODS { fn name(&self) -> &str { - "from-ods" + "from ods" } fn signature(&self) -> Signature { - Signature::build("from-ods").switch( + Signature::build("from ods").switch( "headerless", "don't treat the first row as column names", None, diff --git a/crates/nu-cli/src/commands/from_sqlite.rs b/crates/nu-cli/src/commands/from_sqlite.rs index 21ec57148..c6430f6d5 100644 --- a/crates/nu-cli/src/commands/from_sqlite.rs +++ b/crates/nu-cli/src/commands/from_sqlite.rs @@ -10,11 +10,11 @@ pub struct FromSQLite; impl WholeStreamCommand for FromSQLite { fn name(&self) -> &str { - "from-sqlite" + "from sqlite" } fn signature(&self) -> Signature { - Signature::build("from-sqlite") + Signature::build("from sqlite") } fn usage(&self) -> &str { @@ -34,11 +34,11 @@ pub struct FromDB; impl WholeStreamCommand for FromDB { fn name(&self) -> &str { - "from-db" + "from db" } fn signature(&self) -> Signature { - Signature::build("from-db") + Signature::build("from db") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_ssv.rs b/crates/nu-cli/src/commands/from_ssv.rs index 1284a30cb..04bf09800 100644 --- a/crates/nu-cli/src/commands/from_ssv.rs +++ b/crates/nu-cli/src/commands/from_ssv.rs @@ -17,7 +17,7 @@ pub struct FromSSVArgs { minimum_spaces: Option>, } -const STRING_REPRESENTATION: &str = "from-ssv"; +const STRING_REPRESENTATION: &str = "from ssv"; const DEFAULT_MINIMUM_SPACES: usize = 2; impl WholeStreamCommand for FromSSV { diff --git a/crates/nu-cli/src/commands/from_toml.rs b/crates/nu-cli/src/commands/from_toml.rs index 5454a0163..65b7897c5 100644 --- a/crates/nu-cli/src/commands/from_toml.rs +++ b/crates/nu-cli/src/commands/from_toml.rs @@ -7,11 +7,11 @@ pub struct FromTOML; impl WholeStreamCommand for FromTOML { fn name(&self) -> &str { - "from-toml" + "from toml" } fn signature(&self) -> Signature { - Signature::build("from-toml") + Signature::build("from toml") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_tsv.rs b/crates/nu-cli/src/commands/from_tsv.rs index 425bf302d..ecd484ead 100644 --- a/crates/nu-cli/src/commands/from_tsv.rs +++ b/crates/nu-cli/src/commands/from_tsv.rs @@ -13,11 +13,11 @@ pub struct FromTSVArgs { impl WholeStreamCommand for FromTSV { fn name(&self) -> &str { - "from-tsv" + "from tsv" } fn signature(&self) -> Signature { - Signature::build("from-tsv").switch( + Signature::build("from tsv").switch( "headerless", "don't treat the first row as column names", None, diff --git a/crates/nu-cli/src/commands/from_url.rs b/crates/nu-cli/src/commands/from_url.rs index 4bcbcbf85..84073ac56 100644 --- a/crates/nu-cli/src/commands/from_url.rs +++ b/crates/nu-cli/src/commands/from_url.rs @@ -7,11 +7,11 @@ pub struct FromURL; impl WholeStreamCommand for FromURL { fn name(&self) -> &str { - "from-url" + "from url" } fn signature(&self) -> Signature { - Signature::build("from-url") + Signature::build("from url") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_vcf.rs b/crates/nu-cli/src/commands/from_vcf.rs index 6d4dadfec..82c94fac4 100644 --- a/crates/nu-cli/src/commands/from_vcf.rs +++ b/crates/nu-cli/src/commands/from_vcf.rs @@ -11,11 +11,11 @@ pub struct FromVcf; impl WholeStreamCommand for FromVcf { fn name(&self) -> &str { - "from-vcf" + "from vcf" } fn signature(&self) -> Signature { - Signature::build("from-vcf") + Signature::build("from vcf") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_xlsx.rs b/crates/nu-cli/src/commands/from_xlsx.rs index dbb549f83..983b185ea 100644 --- a/crates/nu-cli/src/commands/from_xlsx.rs +++ b/crates/nu-cli/src/commands/from_xlsx.rs @@ -15,11 +15,11 @@ pub struct FromXLSXArgs { impl WholeStreamCommand for FromXLSX { fn name(&self) -> &str { - "from-xlsx" + "from xlsx" } fn signature(&self) -> Signature { - Signature::build("from-xlsx").switch( + Signature::build("from xlsx").switch( "headerless", "don't treat the first row as column names", None, diff --git a/crates/nu-cli/src/commands/from_xml.rs b/crates/nu-cli/src/commands/from_xml.rs index 10d3c762a..140444cd9 100644 --- a/crates/nu-cli/src/commands/from_xml.rs +++ b/crates/nu-cli/src/commands/from_xml.rs @@ -7,11 +7,11 @@ pub struct FromXML; impl WholeStreamCommand for FromXML { fn name(&self) -> &str { - "from-xml" + "from xml" } fn signature(&self) -> Signature { - Signature::build("from-xml") + Signature::build("from xml") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/from_yaml.rs b/crates/nu-cli/src/commands/from_yaml.rs index 83158eb70..10c16d84f 100644 --- a/crates/nu-cli/src/commands/from_yaml.rs +++ b/crates/nu-cli/src/commands/from_yaml.rs @@ -7,11 +7,11 @@ pub struct FromYAML; impl WholeStreamCommand for FromYAML { fn name(&self) -> &str { - "from-yaml" + "from yaml" } fn signature(&self) -> Signature { - Signature::build("from-yaml") + Signature::build("from yaml") } fn usage(&self) -> &str { @@ -31,11 +31,11 @@ pub struct FromYML; impl WholeStreamCommand for FromYML { fn name(&self) -> &str { - "from-yml" + "from yml" } fn signature(&self) -> Signature { - Signature::build("from-yml") + Signature::build("from yml") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/help.rs b/crates/nu-cli/src/commands/help.rs index c16f8f4df..421068009 100644 --- a/crates/nu-cli/src/commands/help.rs +++ b/crates/nu-cli/src/commands/help.rs @@ -14,7 +14,7 @@ pub struct Help; #[derive(Deserialize)] pub struct HelpArgs { - command: Option>, + rest: Vec>, } impl WholeStreamCommand for Help { @@ -23,11 +23,7 @@ impl WholeStreamCommand for Help { } fn signature(&self) -> Signature { - Signature::build("help").optional( - "command", - SyntaxShape::String, - "the name of command(s) to get help on", - ) + Signature::build("help").rest(SyntaxShape::String, "the name of command to get help on") } fn usage(&self) -> &str { @@ -44,15 +40,19 @@ impl WholeStreamCommand for Help { } fn help( - HelpArgs { command }: HelpArgs, + HelpArgs { rest }: HelpArgs, RunnableContext { registry, name, .. }: RunnableContext, ) -> Result { - if let Some(document) = command { + if let Some(document) = rest.get(0) { let mut help = VecDeque::new(); if document.item == "commands" { let mut sorted_names = registry.names(); sorted_names.sort(); for cmd in sorted_names { + // If it's a subcommand, don't list it during the commands list + if cmd.contains(' ') { + continue; + } let mut short_desc = TaggedDictBuilder::new(name.clone()); let document_tag = document.tag.clone(); let value = command_dict( @@ -82,13 +82,31 @@ fn help( help.push_back(ReturnSuccess::value(short_desc.into_value())); } + } else if rest.len() == 2 { + // Check for a subcommand + let command_name = format!("{} {}", rest[0].item, rest[1].item); + if let Some(command) = registry.get_command(&command_name) { + return Ok(get_help( + &command.name(), + &command.usage(), + command.signature(), + ®istry, + ) + .into()); + } } else if let Some(command) = registry.get_command(&document.item) { - return Ok(get_help(&command.name(), &command.usage(), command.signature()).into()); + return Ok(get_help( + &command.name(), + &command.usage(), + command.signature(), + ®istry, + ) + .into()); } else { return Err(ShellError::labeled_error( "Can't find command (use 'help commands' for full list)", "can't find command", - document.tag, + document.tag.span, )); } let help = futures::stream::iter(help); @@ -128,6 +146,7 @@ pub(crate) fn get_help( cmd_name: &str, cmd_usage: &str, cmd_sig: Signature, + registry: &CommandRegistry, ) -> impl Into { let mut help = VecDeque::new(); let mut long_desc = String::new(); @@ -137,6 +156,15 @@ pub(crate) fn get_help( let signature = cmd_sig; + let mut subcommands = String::new(); + for name in registry.names() { + if name.starts_with(&format!("{} ", cmd_name)) { + let subcommand = registry.get_command(&name).expect("This shouldn't happen"); + + subcommands.push_str(&format!(" {} - {}\n", name, subcommand.usage())); + } + } + let mut one_liner = String::new(); one_liner.push_str(&signature.name); one_liner.push_str(" "); @@ -156,14 +184,23 @@ pub(crate) fn get_help( one_liner.push_str(" ...args"); } + if !subcommands.is_empty() { + one_liner.push_str(" "); + } + if !signature.named.is_empty() { one_liner.push_str("{flags} "); } long_desc.push_str(&format!("\nUsage:\n > {}\n", one_liner)); + if !subcommands.is_empty() { + long_desc.push_str("\nSubcommands:\n"); + long_desc.push_str(&subcommands); + } + if !signature.positional.is_empty() || signature.rest_positional.is_some() { - long_desc.push_str("\nparameters:\n"); + long_desc.push_str("\nParameters:\n"); for positional in signature.positional { match positional.0 { PositionalType::Mandatory(name, _m) => { @@ -180,7 +217,7 @@ pub(crate) fn get_help( } } if !signature.named.is_empty() { - long_desc.push_str("\nflags:\n"); + long_desc.push_str("\nFlags:\n"); for (flag, ty) in signature.named { let msg = match ty.0 { NamedType::Switch(s) => { diff --git a/crates/nu-cli/src/commands/save.rs b/crates/nu-cli/src/commands/save.rs index d625090a1..e59865808 100644 --- a/crates/nu-cli/src/commands/save.rs +++ b/crates/nu-cli/src/commands/save.rs @@ -221,7 +221,7 @@ fn save( let content : Result, ShellError> = 'scope: loop { break if !save_raw { if let Some(extension) = full_path.extension() { - let command_name = format!("to-{}", extension.to_string_lossy()); + let command_name = format!("to {}", extension.to_string_lossy()); if let Some(converter) = registry.get_command(&command_name) { let new_args = RawCommandArgs { host, diff --git a/crates/nu-cli/src/commands/to.rs b/crates/nu-cli/src/commands/to.rs new file mode 100644 index 000000000..3df721e9c --- /dev/null +++ b/crates/nu-cli/src/commands/to.rs @@ -0,0 +1,31 @@ +use crate::commands::WholeStreamCommand; +use crate::prelude::*; +use nu_errors::ShellError; +use nu_protocol::Signature; + +pub struct To; + +impl WholeStreamCommand for To { + fn name(&self) -> &str { + "to" + } + + fn signature(&self) -> Signature { + Signature::build("to") + } + + fn usage(&self) -> &str { + "Convert table into an output format." + } + + fn run( + &self, + _args: CommandArgs, + registry: &CommandRegistry, + ) -> Result { + Ok( + crate::commands::help::get_help(self.name(), self.usage(), self.signature(), registry) + .into(), + ) + } +} diff --git a/crates/nu-cli/src/commands/to_bson.rs b/crates/nu-cli/src/commands/to_bson.rs index a3ef3a235..2ac9d6929 100644 --- a/crates/nu-cli/src/commands/to_bson.rs +++ b/crates/nu-cli/src/commands/to_bson.rs @@ -12,11 +12,11 @@ pub struct ToBSON; impl WholeStreamCommand for ToBSON { fn name(&self) -> &str { - "to-bson" + "to bson" } fn signature(&self) -> Signature { - Signature::build("to-bson") + Signature::build("to bson") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/to_csv.rs b/crates/nu-cli/src/commands/to_csv.rs index da82fd0b7..d789ca46a 100644 --- a/crates/nu-cli/src/commands/to_csv.rs +++ b/crates/nu-cli/src/commands/to_csv.rs @@ -14,11 +14,11 @@ pub struct ToCSVArgs { impl WholeStreamCommand for ToCSV { fn name(&self) -> &str { - "to-csv" + "to csv" } fn signature(&self) -> Signature { - Signature::build("to-csv") + Signature::build("to csv") .named( "separator", SyntaxShape::String, diff --git a/crates/nu-cli/src/commands/to_html.rs b/crates/nu-cli/src/commands/to_html.rs index 1287a6d81..bd5f3bef2 100644 --- a/crates/nu-cli/src/commands/to_html.rs +++ b/crates/nu-cli/src/commands/to_html.rs @@ -10,11 +10,11 @@ pub struct ToHTML; impl WholeStreamCommand for ToHTML { fn name(&self) -> &str { - "to-html" + "to html" } fn signature(&self) -> Signature { - Signature::build("to-html") + Signature::build("to html") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/to_json.rs b/crates/nu-cli/src/commands/to_json.rs index c4a16ad4a..dc0b71c67 100644 --- a/crates/nu-cli/src/commands/to_json.rs +++ b/crates/nu-cli/src/commands/to_json.rs @@ -7,11 +7,11 @@ pub struct ToJSON; impl WholeStreamCommand for ToJSON { fn name(&self) -> &str { - "to-json" + "to json" } fn signature(&self) -> Signature { - Signature::build("to-json") + Signature::build("to json") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/to_md.rs b/crates/nu-cli/src/commands/to_md.rs index 26cf4d396..0bc5b1a6f 100644 --- a/crates/nu-cli/src/commands/to_md.rs +++ b/crates/nu-cli/src/commands/to_md.rs @@ -9,11 +9,11 @@ pub struct ToMarkdown; impl WholeStreamCommand for ToMarkdown { fn name(&self) -> &str { - "to-md" + "to md" } fn signature(&self) -> Signature { - Signature::build("to-md") + Signature::build("to md") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/to_sqlite.rs b/crates/nu-cli/src/commands/to_sqlite.rs index 06e009fd9..4eedd7104 100644 --- a/crates/nu-cli/src/commands/to_sqlite.rs +++ b/crates/nu-cli/src/commands/to_sqlite.rs @@ -10,11 +10,11 @@ pub struct ToSQLite; impl WholeStreamCommand for ToSQLite { fn name(&self) -> &str { - "to-sqlite" + "to sqlite" } fn signature(&self) -> Signature { - Signature::build("to-sqlite") + Signature::build("to sqlite") } fn usage(&self) -> &str { @@ -38,11 +38,11 @@ pub struct ToDB; impl WholeStreamCommand for ToDB { fn name(&self) -> &str { - "to-db" + "to db" } fn signature(&self) -> Signature { - Signature::build("to-db") + Signature::build("to db") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/to_toml.rs b/crates/nu-cli/src/commands/to_toml.rs index df523b413..cda9c9efb 100644 --- a/crates/nu-cli/src/commands/to_toml.rs +++ b/crates/nu-cli/src/commands/to_toml.rs @@ -7,11 +7,11 @@ pub struct ToTOML; impl WholeStreamCommand for ToTOML { fn name(&self) -> &str { - "to-toml" + "to toml" } fn signature(&self) -> Signature { - Signature::build("to-toml") + Signature::build("to toml") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/to_tsv.rs b/crates/nu-cli/src/commands/to_tsv.rs index 2ab9c1352..bcbf655fb 100644 --- a/crates/nu-cli/src/commands/to_tsv.rs +++ b/crates/nu-cli/src/commands/to_tsv.rs @@ -13,11 +13,11 @@ pub struct ToTSVArgs { impl WholeStreamCommand for ToTSV { fn name(&self) -> &str { - "to-tsv" + "to tsv" } fn signature(&self) -> Signature { - Signature::build("to-tsv").switch( + Signature::build("to tsv").switch( "headerless", "do not output the column names as the first row", None, diff --git a/crates/nu-cli/src/commands/to_url.rs b/crates/nu-cli/src/commands/to_url.rs index 33db62658..7b42ec61c 100644 --- a/crates/nu-cli/src/commands/to_url.rs +++ b/crates/nu-cli/src/commands/to_url.rs @@ -7,11 +7,11 @@ pub struct ToURL; impl WholeStreamCommand for ToURL { fn name(&self) -> &str { - "to-url" + "to url" } fn signature(&self) -> Signature { - Signature::build("to-url") + Signature::build("to url") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/to_yaml.rs b/crates/nu-cli/src/commands/to_yaml.rs index 732fc8b8b..7c834e57f 100644 --- a/crates/nu-cli/src/commands/to_yaml.rs +++ b/crates/nu-cli/src/commands/to_yaml.rs @@ -7,11 +7,11 @@ pub struct ToYAML; impl WholeStreamCommand for ToYAML { fn name(&self) -> &str { - "to-yaml" + "to yaml" } fn signature(&self) -> Signature { - Signature::build("to-yaml") + Signature::build("to yaml") } fn usage(&self) -> &str { diff --git a/crates/nu-cli/tests/commands/alias.rs b/crates/nu-cli/tests/commands/alias.rs index 170c8aac1..64d56e9ed 100644 --- a/crates/nu-cli/tests/commands/alias.rs +++ b/crates/nu-cli/tests/commands/alias.rs @@ -8,7 +8,7 @@ fn alias_args_work() { cwd: dirs.root(), r#" alias double_echo [a b] {echo $a $b} - double_echo 1 2 | to-json + double_echo 1 2 | to json "# ); diff --git a/crates/nu-cli/tests/commands/compact.rs b/crates/nu-cli/tests/commands/compact.rs index 8e5bc8fa4..373958565 100644 --- a/crates/nu-cli/tests/commands/compact.rs +++ b/crates/nu-cli/tests/commands/compact.rs @@ -40,7 +40,7 @@ fn discards_empty_rows_by_default() { cwd: dirs.test(), pipeline( r#" echo "[1,2,3,14,null]" - | from-json + | from json | compact | count | echo $it diff --git a/crates/nu-cli/tests/commands/drop.rs b/crates/nu-cli/tests/commands/drop.rs index 947dc9975..625f08ca6 100644 --- a/crates/nu-cli/tests/commands/drop.rs +++ b/crates/nu-cli/tests/commands/drop.rs @@ -4,7 +4,7 @@ use nu_test_support::nu; fn drop_rows() { let actual = nu!( cwd: "tests/fixtures/formats", - r#"echo '[{"foo": 3}, {"foo": 8}, {"foo": 4}]' | from-json | drop 2 | get foo | sum | echo $it"# + r#"echo '[{"foo": 3}, {"foo": 8}, {"foo": 4}]' | from json | drop 2 | get foo | sum | echo $it"# ); assert_eq!(actual, "3"); diff --git a/crates/nu-cli/tests/commands/each.rs b/crates/nu-cli/tests/commands/each.rs index fed8abfff..3700ebff8 100644 --- a/crates/nu-cli/tests/commands/each.rs +++ b/crates/nu-cli/tests/commands/each.rs @@ -5,7 +5,7 @@ fn each_works_separately() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" - echo [1 2 3] | each { echo $it 10 | sum } | to-json | echo $it + echo [1 2 3] | each { echo $it 10 | sum } | to json | echo $it "# )); diff --git a/crates/nu-cli/tests/commands/get.rs b/crates/nu-cli/tests/commands/get.rs index 5b80287cb..c824c6e9a 100644 --- a/crates/nu-cli/tests/commands/get.rs +++ b/crates/nu-cli/tests/commands/get.rs @@ -240,7 +240,7 @@ fn errors_fetching_by_index_out_of_bounds() { fn quoted_column_access() { let actual = nu!( cwd: "tests/fixtures/formats", - r#"echo '[{"foo bar": {"baz": 4}}]' | from-json | get "foo bar".baz | echo $it"# + r#"echo '[{"foo bar": {"baz": 4}}]' | from json | get "foo bar".baz | echo $it"# ); assert_eq!(actual, "4"); diff --git a/crates/nu-cli/tests/commands/headers.rs b/crates/nu-cli/tests/commands/headers.rs index be5ffb5c7..607d19d40 100644 --- a/crates/nu-cli/tests/commands/headers.rs +++ b/crates/nu-cli/tests/commands/headers.rs @@ -9,7 +9,7 @@ fn headers_uses_first_row_as_header() { | get Sheet1 | headers | get header0 - | from-json"# + | from json"# )); assert_eq!(actual, "r1c0r2c0") @@ -24,7 +24,7 @@ fn headers_adds_missing_column_name() { | get Sheet1 | headers | get Column1 - | from-json"# + | from json"# )); assert_eq!(actual, "r1c1r2c1") diff --git a/crates/nu-cli/tests/commands/math.rs b/crates/nu-cli/tests/commands/math.rs index 34d20f55f..9080cb0a6 100644 --- a/crates/nu-cli/tests/commands/math.rs +++ b/crates/nu-cli/tests/commands/math.rs @@ -125,7 +125,7 @@ fn compound_where() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" - echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from-json | where a == 2 && b == 1 | to-json + echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where a == 2 && b == 1 | to json "# )); @@ -137,7 +137,7 @@ fn compound_where_paren() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" - echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from-json | where (a == 2 && b == 1) || b == 2 | to-json + echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where (a == 2 && b == 1) || b == 2 | to json "# )); diff --git a/crates/nu-cli/tests/commands/uniq.rs b/crates/nu-cli/tests/commands/uniq.rs index 8988a4583..4271bc16d 100644 --- a/crates/nu-cli/tests/commands/uniq.rs +++ b/crates/nu-cli/tests/commands/uniq.rs @@ -131,7 +131,7 @@ fn uniq_when_keys_out_of_order() { cwd: "tests/fixtures/formats", pipeline( r#" echo '[{"a": "a", "b": [1,2,3]},{"b": [1,2,3], "a": "a"}]' - | from-json + | from json | uniq | count | echo $it diff --git a/crates/nu-cli/tests/commands/where_.rs b/crates/nu-cli/tests/commands/where_.rs index 764a972da..d45439d29 100644 --- a/crates/nu-cli/tests/commands/where_.rs +++ b/crates/nu-cli/tests/commands/where_.rs @@ -14,7 +14,7 @@ fn filters_by_unit_size_comparison() { fn filters_with_nothing_comparison() { let actual = nu!( cwd: "tests/fixtures/formats", - r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from-json | where foo > 1 | get foo | sum | echo $it"# + r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from json | where foo > 1 | get foo | sum | echo $it"# ); assert_eq!(actual, "7"); @@ -24,7 +24,7 @@ fn filters_with_nothing_comparison() { fn where_in_table() { let actual = nu!( cwd: "tests/fixtures/formats", - r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from-json | where name in: ["foo"] | get size | sum | echo $it"# + r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name in: ["foo"] | get size | sum | echo $it"# ); assert_eq!(actual, "5"); @@ -34,7 +34,7 @@ fn where_in_table() { fn where_not_in_table() { let actual = nu!( cwd: "tests/fixtures/formats", - r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from-json | where name not-in: ["foo"] | get size | sum | echo $it"# + r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name not-in: ["foo"] | get size | sum | echo $it"# ); assert_eq!(actual, "4"); diff --git a/crates/nu-cli/tests/commands/wrap.rs b/crates/nu-cli/tests/commands/wrap.rs index 60e90183e..02a0ebb66 100644 --- a/crates/nu-cli/tests/commands/wrap.rs +++ b/crates/nu-cli/tests/commands/wrap.rs @@ -19,7 +19,7 @@ fn wrap_rows_into_a_row() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.txt - | from-csv + | from csv | wrap caballeros | get caballeros | nth 0 @@ -49,7 +49,7 @@ fn wrap_rows_into_a_table() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.txt - | from-csv + | from csv | get last_name | wrap caballero | nth 2 diff --git a/crates/nu-cli/tests/format_conversions/bson.rs b/crates/nu-cli/tests/format_conversions/bson.rs index febcf2619..3fc39e821 100644 --- a/crates/nu-cli/tests/format_conversions/bson.rs +++ b/crates/nu-cli/tests/format_conversions/bson.rs @@ -6,8 +6,8 @@ fn table_to_bson_and_back_into_table() { cwd: "tests/fixtures/formats", pipeline( r#" open sample.bson - | to-bson - | from-bson + | to bson + | from bson | get root | get 1.b | echo $it diff --git a/crates/nu-cli/tests/format_conversions/csv.rs b/crates/nu-cli/tests/format_conversions/csv.rs index 4b9569b3f..17e2f14c0 100644 --- a/crates/nu-cli/tests/format_conversions/csv.rs +++ b/crates/nu-cli/tests/format_conversions/csv.rs @@ -6,7 +6,7 @@ use nu_test_support::{nu, pipeline}; fn table_to_csv_text_and_from_csv_text_back_into_table() { let actual = nu!( cwd: "tests/fixtures/formats", - "open caco3_plastics.csv | to-csv | from-csv | first 1 | get origin | echo $it" + "open caco3_plastics.csv | to csv | from csv | first 1 | get origin | echo $it" ); assert_eq!(actual, "SPAIN"); @@ -32,7 +32,7 @@ fn table_to_csv_text() { | trim | split-column "," a b c d origin | last 1 - | to-csv + | to csv | lines | nth 1 | echo $it @@ -63,7 +63,7 @@ fn table_to_csv_text_skipping_headers_after_conversion() { | trim | split-column "," a b c d origin | last 1 - | to-csv --headerless + | to csv --headerless | echo $it "# )); @@ -117,7 +117,7 @@ fn from_csv_text_to_table() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.txt - | from-csv + | from csv | get rusty_luck | count | echo $it @@ -145,7 +145,7 @@ fn from_csv_text_with_separator_to_table() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.txt - | from-csv --separator ';' + | from csv --separator ';' | get rusty_luck | count | echo $it @@ -173,7 +173,7 @@ fn from_csv_text_with_tab_separator_to_table() { cwd: dirs.test(), pipeline( r#" open los_tres_caballeros.txt - | from-csv --separator '\t' + | from csv --separator '\t' | get rusty_luck | count | echo $it @@ -200,7 +200,7 @@ fn from_csv_text_skipping_headers_to_table() { cwd: dirs.test(), pipeline( r#" open los_tres_amigos.txt - | from-csv --headerless + | from csv --headerless | get Column3 | count | echo $it diff --git a/crates/nu-cli/tests/format_conversions/html.rs b/crates/nu-cli/tests/format_conversions/html.rs index 07cfc5b66..d12eec98d 100644 --- a/crates/nu-cli/tests/format_conversions/html.rs +++ b/crates/nu-cli/tests/format_conversions/html.rs @@ -5,7 +5,7 @@ fn out_html_simple() { let actual = nu!( cwd: ".", pipeline( r#" - echo 3 | to-html + echo 3 | to html "# )); @@ -17,7 +17,7 @@ fn out_html_table() { let actual = nu!( cwd: ".", pipeline( r#" - echo '{"name": "jason"}' | from-json | to-html + echo '{"name": "jason"}' | from json | to html "# )); diff --git a/crates/nu-cli/tests/format_conversions/ics.rs b/crates/nu-cli/tests/format_conversions/ics.rs index 9503ab91c..9d2d0f7e1 100644 --- a/crates/nu-cli/tests/format_conversions/ics.rs +++ b/crates/nu-cli/tests/format_conversions/ics.rs @@ -86,7 +86,7 @@ fn from_ics_text_to_table() { cwd: dirs.test(), pipeline( r#" open calendar.txt - | from-ics + | from ics | get events | get properties | where name == "SUMMARY" diff --git a/crates/nu-cli/tests/format_conversions/json.rs b/crates/nu-cli/tests/format_conversions/json.rs index 9788afc12..3f056839f 100644 --- a/crates/nu-cli/tests/format_conversions/json.rs +++ b/crates/nu-cli/tests/format_conversions/json.rs @@ -8,8 +8,8 @@ fn table_to_json_text_and_from_json_text_back_into_table() { cwd: "tests/fixtures/formats", pipeline( r#" open sgml_description.json - | to-json - | from-json + | to json + | from json | get glossary.GlossDiv.GlossList.GlossEntry.GlossSee | echo $it "# @@ -37,7 +37,7 @@ fn from_json_text_to_table() { let actual = nu!( cwd: dirs.test(), - "open katz.txt | from-json | get katz | get rusty_luck | count | echo $it" + "open katz.txt | from json | get katz | get rusty_luck | count | echo $it" ); assert_eq!(actual, "4"); @@ -61,7 +61,7 @@ fn from_json_text_recognizing_objects_independently_to_table() { cwd: dirs.test(), pipeline( r#" open katz.txt - | from-json -o + | from json -o | where name == "GorbyPuff" | get rusty_luck | echo $it @@ -90,8 +90,8 @@ fn table_to_json_text() { | lines | split-column "," name luck | pick name - | to-json - | from-json + | to json + | from json | nth 0 | get name | echo $it diff --git a/crates/nu-cli/tests/format_conversions/markdown.rs b/crates/nu-cli/tests/format_conversions/markdown.rs index c7800f3bb..2e79c57fd 100644 --- a/crates/nu-cli/tests/format_conversions/markdown.rs +++ b/crates/nu-cli/tests/format_conversions/markdown.rs @@ -5,7 +5,7 @@ fn out_md_simple() { let actual = nu!( cwd: ".", pipeline( r#" - echo 3 | to-md + echo 3 | to md "# )); @@ -17,7 +17,7 @@ fn out_md_table() { let actual = nu!( cwd: ".", pipeline( r#" - echo '{"name": "jason"}' | from-json | to-md + echo '{"name": "jason"}' | from json | to md "# )); diff --git a/crates/nu-cli/tests/format_conversions/sqlite.rs b/crates/nu-cli/tests/format_conversions/sqlite.rs index abe83961b..15843707a 100644 --- a/crates/nu-cli/tests/format_conversions/sqlite.rs +++ b/crates/nu-cli/tests/format_conversions/sqlite.rs @@ -6,8 +6,8 @@ fn table_to_sqlite_and_back_into_table() { cwd: "tests/fixtures/formats", pipeline( r#" open sample.db - | to-sqlite - | from-sqlite + | to sqlite + | from sqlite | get table_values | nth 2 | get x diff --git a/crates/nu-cli/tests/format_conversions/ssv.rs b/crates/nu-cli/tests/format_conversions/ssv.rs index 91854f384..7287cc807 100644 --- a/crates/nu-cli/tests/format_conversions/ssv.rs +++ b/crates/nu-cli/tests/format_conversions/ssv.rs @@ -19,7 +19,7 @@ fn from_ssv_text_to_table() { cwd: dirs.test(), pipeline( r#" open oc_get_svc.txt - | from-ssv + | from ssv | nth 0 | get IP | echo $it @@ -47,7 +47,7 @@ fn from_ssv_text_to_table_with_separator_specified() { cwd: dirs.test(), pipeline( r#" open oc_get_svc.txt - | from-ssv --minimum-spaces 3 + | from ssv --minimum-spaces 3 | nth 0 | get IP | echo $it @@ -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 -a + | from ssv --headerless -a | first | get Column1 | echo $it @@ -85,7 +85,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 + | from ssv --headerless | first | get Column1 | echo $it diff --git a/crates/nu-cli/tests/format_conversions/toml.rs b/crates/nu-cli/tests/format_conversions/toml.rs index d634ee300..e1eb64c88 100644 --- a/crates/nu-cli/tests/format_conversions/toml.rs +++ b/crates/nu-cli/tests/format_conversions/toml.rs @@ -6,8 +6,8 @@ fn table_to_toml_text_and_from_toml_text_back_into_table() { cwd: "tests/fixtures/formats", pipeline( r#" open cargo_sample.toml - | to-toml - | from-toml + | to toml + | from toml | get package.name | echo $it "# diff --git a/crates/nu-cli/tests/format_conversions/tsv.rs b/crates/nu-cli/tests/format_conversions/tsv.rs index af4413844..785be1992 100644 --- a/crates/nu-cli/tests/format_conversions/tsv.rs +++ b/crates/nu-cli/tests/format_conversions/tsv.rs @@ -6,7 +6,7 @@ use nu_test_support::{nu, pipeline}; fn table_to_tsv_text_and_from_tsv_text_back_into_table() { let actual = nu!( cwd: "tests/fixtures/formats", - "open caco3_plastics.tsv | to-tsv | from-tsv | first 1 | get origin | echo $it" + "open caco3_plastics.tsv | to tsv | from tsv | first 1 | get origin | echo $it" ); assert_eq!(actual, "SPAIN"); @@ -16,7 +16,7 @@ fn table_to_tsv_text_and_from_tsv_text_back_into_table() { fn table_to_tsv_text_and_from_tsv_text_back_into_table_using_csv_separator() { let actual = nu!( cwd: "tests/fixtures/formats", - r"open caco3_plastics.tsv | to-tsv | from-csv --separator '\t' | first 1 | get origin | echo $it" + r"open caco3_plastics.tsv | to tsv | from csv --separator '\t' | first 1 | get origin | echo $it" ); assert_eq!(actual, "SPAIN"); @@ -41,7 +41,7 @@ fn table_to_tsv_text() { | lines | split-column "\t" a b c d origin | last 1 - | to-tsv + | to tsv | lines | nth 1 | echo $it @@ -71,7 +71,7 @@ fn table_to_tsv_text_skipping_headers_after_conversion() { | lines | split-column "\t" a b c d origin | last 1 - | to-tsv --headerless + | to tsv --headerless | echo $it "# )); @@ -97,7 +97,7 @@ fn from_tsv_text_to_table() { cwd: dirs.test(), pipeline( r#" open los_tres_amigos.txt - | from-tsv + | from tsv | get rusty_luck | count | echo $it @@ -124,7 +124,7 @@ fn from_tsv_text_skipping_headers_to_table() { cwd: dirs.test(), pipeline( r#" open los_tres_amigos.txt - | from-tsv --headerless + | from tsv --headerless | get Column3 | count | echo $it diff --git a/crates/nu-cli/tests/format_conversions/url.rs b/crates/nu-cli/tests/format_conversions/url.rs index 90ce141a2..1312bda77 100644 --- a/crates/nu-cli/tests/format_conversions/url.rs +++ b/crates/nu-cli/tests/format_conversions/url.rs @@ -6,8 +6,8 @@ fn can_encode_and_decode_urlencoding() { cwd: "tests/fixtures/formats", pipeline( r#" open sample.url - | to-url - | from-url + | to url + | from url | get cheese | echo $it "# diff --git a/crates/nu-cli/tests/format_conversions/vcf.rs b/crates/nu-cli/tests/format_conversions/vcf.rs index 4d86224b2..be59cca74 100644 --- a/crates/nu-cli/tests/format_conversions/vcf.rs +++ b/crates/nu-cli/tests/format_conversions/vcf.rs @@ -70,7 +70,7 @@ fn from_vcf_text_to_table() { cwd: dirs.test(), pipeline( r#" open contacts.txt - | from-vcf + | from vcf | get properties | where name == "EMAIL" | first diff --git a/crates/nu-cli/tests/format_conversions/yaml.rs b/crates/nu-cli/tests/format_conversions/yaml.rs index 663b2fec4..fce047e3c 100644 --- a/crates/nu-cli/tests/format_conversions/yaml.rs +++ b/crates/nu-cli/tests/format_conversions/yaml.rs @@ -6,8 +6,8 @@ fn table_to_yaml_text_and_from_yaml_text_back_into_table() { cwd: "tests/fixtures/formats", pipeline( r#" open appveyor.yml - | to-yaml - | from-yaml + | to yaml + | from yaml | get environment.global.PROJECT_NAME | echo $it "# diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index b5e516454..5505a6947 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -848,16 +848,22 @@ fn parse_internal_command( lite_cmd: &LiteCommand, registry: &dyn SignatureRegistry, signature: &Signature, + mut idx: usize, ) -> (InternalCommand, Option) { // This is a known internal command, so we need to work with the arguments and parse them according to the expected types - let mut internal_command = InternalCommand::new( - lite_cmd.name.item.clone(), - lite_cmd.name.span, - lite_cmd.span(), - ); + + let (name, name_span) = if idx == 0 { + (lite_cmd.name.item.clone(), lite_cmd.name.span) + } else { + ( + format!("{} {}", lite_cmd.name.item, lite_cmd.args[0].item), + Span::new(lite_cmd.name.span.start(), lite_cmd.args[0].span.end()), + ) + }; + + let mut internal_command = InternalCommand::new(name, name_span, lite_cmd.span()); internal_command.args.set_initial_flags(&signature); - let mut idx = 0; let mut current_positional = 0; let mut named = NamedArguments::new(); let mut positional = vec![]; @@ -1051,12 +1057,31 @@ fn classify_pipeline( garbage(lite_cmd.span()) }; commands.push(ClassifiedCommand::Expr(Box::new(expr))) - } else if let Some(signature) = registry.get(&lite_cmd.name.item) { - let (internal_command, err) = parse_internal_command(&lite_cmd, registry, &signature); - - error = error.or(err); - commands.push(ClassifiedCommand::Internal(internal_command)) } else { + if !lite_cmd.args.is_empty() { + // Check if it's a sub-command + if let Some(signature) = + registry.get(&format!("{} {}", lite_cmd.name.item, lite_cmd.args[0].item)) + { + let (internal_command, err) = + parse_internal_command(&lite_cmd, registry, &signature, 1); + + error = error.or(err); + commands.push(ClassifiedCommand::Internal(internal_command)); + continue; + } + } + + // Check if it's an internal command + if let Some(signature) = registry.get(&lite_cmd.name.item) { + let (internal_command, err) = + parse_internal_command(&lite_cmd, registry, &signature, 0); + + error = error.or(err); + commands.push(ClassifiedCommand::Internal(internal_command)); + continue; + } + let name = lite_cmd.name.clone().map(|v| { let trimmed = trim_quotes(&v); expand_path(&trimmed).to_string() diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index a7e38bfb8..5986f6171 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -33,10 +33,13 @@ pub struct InternalCommand { impl InternalCommand { pub fn new(name: String, name_span: Span, full_span: Span) -> InternalCommand { InternalCommand { - name: name.clone(), + name, name_span, args: crate::hir::Call::new( - Box::new(SpannedExpression::new(Expression::string(name), name_span)), + Box::new(SpannedExpression::new( + Expression::Command(name_span), + name_span, + )), full_span, ), } diff --git a/docs/commands/save.md b/docs/commands/save.md index fe1ce66ef..461fb8772 100644 --- a/docs/commands/save.md +++ b/docs/commands/save.md @@ -21,10 +21,10 @@ You can save the name of files in a directory like this: > ls | where type == File | pick name | save filenames.csv ``` -Or you can format it in supported formats using one of the `to-*` commands: +Or you can format it in supported formats using one of the `to` commands: ```shell -> ls | where type == File | pick name | to-csv | save filenames +> ls | where type == File | pick name | to csv | save filenames ``` `filename.csv` and `filenames` are both `csv` formatted files. Nu auto-converts the format if a supported file extension is given. \ No newline at end of file diff --git a/tests/plugins/core_str.rs b/tests/plugins/core_str.rs index d2f69563e..bcafb30be 100644 --- a/tests/plugins/core_str.rs +++ b/tests/plugins/core_str.rs @@ -119,7 +119,7 @@ fn converts_to_int() { cwd: "tests/fixtures/formats", pipeline( r#" echo '{number_as_string: "1"}' - | from-json + | from json | str number_as_string --to-int | rename number | where number == 1 diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index 387f10b46..1a15e8cda 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -48,13 +48,6 @@ fn automatically_change_directory_with_trailing_slash_and_same_name_as_command() }) } -// #[test] -// fn correctly_escape_external_arguments() { -// let actual = nu!(cwd: ".", r#"^echo '[{"foo": "bar"}]' | from-json | to-json"#); - -// assert_eq!(actual, "{\"foo\":\"bar\"}"); -// } - #[test] fn correctly_escape_external_arguments() { let actual = nu!(cwd: ".", r#"^echo '$0'"#); diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index d08f0fefd..04027aabd 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -152,7 +152,7 @@ mod tilde_expansion { let actual = nu!( cwd: dirs.test(), pipeline( r#" - ls | sort-by name | group-by type | each { get File.name | echo $it } | to-json + ls | sort-by name | group-by type | each { get File.name | echo $it } | to json "# ));