diff --git a/crates/nu-command/src/strings/encode_decode/base64.rs b/crates/nu-command/src/strings/encode_decode/base64.rs index 95f93a3ea0..e9d5c4f5a5 100644 --- a/crates/nu-command/src/strings/encode_decode/base64.rs +++ b/crates/nu-command/src/strings/encode_decode/base64.rs @@ -161,7 +161,7 @@ fn action( } other => Value::Error { error: ShellError::TypeMismatch( - format!("value is {}, not string", other.get_type()), + format!("string or binary, not {}", other.get_type()), other.span().unwrap_or(command_span), ), }, diff --git a/crates/nu-command/src/strings/encode_decode/encode_base64.rs b/crates/nu-command/src/strings/encode_decode/encode_base64.rs index 542beab3f4..c017cdd2f7 100644 --- a/crates/nu-command/src/strings/encode_decode/encode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/encode_base64.rs @@ -15,7 +15,10 @@ impl Command for EncodeBase64 { fn signature(&self) -> Signature { Signature::build("encode base64") - .input_output_types(vec![(Type::String, Type::String)]) + .input_output_types(vec![ + (Type::String, Type::String), + (Type::Binary, Type::String), + ]) .vectorizes_over_list(true) .named( "character-set", @@ -33,18 +36,23 @@ impl Command for EncodeBase64 { } fn usage(&self) -> &str { - "Base64 encode a value" + "Encode a string or binary value using Base64" } fn examples(&self) -> Vec { vec![ Example { - description: "Base64 encode a string with default settings", + description: "Encode binary data", + example: "0x[09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0] | encode base64", + result: Some(Value::string("CfkRAp1041vYQVbFY1aIwA==", Span::test_data())), + }, + Example { + description: "Encode a string with default settings", example: "'Some Data' | encode base64", result: Some(Value::string("U29tZSBEYXRh", Span::test_data())), }, Example { - description: "Base64 encode a string with the binhex character set", + description: "Encode a string with the binhex character set", example: "'Some Data' | encode base64 --character-set binhex", result: Some(Value::string(r#"7epXB5"%A@4J"#, Span::test_data())), },