From 5d2ef0faf1c8d17f6d5af4fc82689eedb62956df Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:39:24 -0500 Subject: [PATCH] add input_output_type to ansi command (#9817) # Description This PR fixes this not working `ansi --list | columns`. I originally thought that this was a problem with `columns` but it turned out to be a problem with the input output type of `ansi`. Since `ansi` was only allowed to return strings, `columns` thought it was getting a string, but it was a table. closes #9808 tracking #9812 # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/platform/ansi/ansi_.rs | 5 ++++- crates/nu-command/tests/commands/platform/ansi_.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/platform/ansi/ansi_.rs b/crates/nu-command/src/platform/ansi/ansi_.rs index 9912e0bed..a60a6897d 100644 --- a/crates/nu-command/src/platform/ansi/ansi_.rs +++ b/crates/nu-command/src/platform/ansi/ansi_.rs @@ -507,7 +507,9 @@ impl Command for AnsiCommand { fn signature(&self) -> Signature { Signature::build("ansi") - .input_output_types(vec![(Type::Nothing, Type::String)]) + .input_output_types(vec![ + (Type::Nothing, Type::String), + (Type::Nothing, Type::Table(vec![]))]) .optional( "code", SyntaxShape::Any, @@ -524,6 +526,7 @@ impl Command for AnsiCommand { Some('o'), ) .switch("list", "list available ansi code names", Some('l')) + .allow_variants_without_examples(true) .category(Category::Platform) } diff --git a/crates/nu-command/tests/commands/platform/ansi_.rs b/crates/nu-command/tests/commands/platform/ansi_.rs index 7e01f930d..8531e0bd4 100644 --- a/crates/nu-command/tests/commands/platform/ansi_.rs +++ b/crates/nu-command/tests/commands/platform/ansi_.rs @@ -10,3 +10,14 @@ fn test_ansi_shows_error_on_escape() { assert!(actual.err.contains("no need for escape characters")) } + +#[test] +fn test_ansi_list_outputs_table() { + let actual = nu!(pipeline( + r#" + ansi --list | length + "# + )); + + assert_eq!(actual.out, "424"); +}