Examples
This commit is contained in:
parent
577f689d27
commit
2f0b961ab3
|
@ -31,7 +31,23 @@ impl Command for DecodeBase32 {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Decode arbitrary binary data",
|
||||
example: r#""AEBAGBAF" | decode base32"#,
|
||||
result: Some(Value::test_binary(vec![1, 2, 3, 4, 5])),
|
||||
},
|
||||
Example {
|
||||
description: "Decode an encoded string",
|
||||
example: r#""NBUQ====" | decode base32 | decode"#,
|
||||
result: Some(Value::test_string("hi")),
|
||||
},
|
||||
Example {
|
||||
description: "Parse a string without padding",
|
||||
example: r#""NBUQ" | decode base32 --nopad"#,
|
||||
result: Some(Value::test_binary(vec![68, 69])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
@ -96,7 +112,23 @@ impl Command for EncodeBase32 {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Encode a binary value",
|
||||
example: r#"0x[01 02 10] | encode base32"#,
|
||||
result: Some(Value::test_string("AEBBA===")),
|
||||
},
|
||||
Example {
|
||||
description: "Encode a string",
|
||||
example: r#""hello there" | encode base32"#,
|
||||
result: Some(Value::test_string("NBSWY3DPEB2GQZLSMU======")),
|
||||
},
|
||||
Example {
|
||||
description: "Don't apply padding to the output",
|
||||
example: r#""hi" | encode base32 --nopad"#,
|
||||
result: Some(Value::test_string("NBUQ")),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
|
|
@ -32,7 +32,23 @@ impl Command for DecodeBase32Hex {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Decode arbitrary binary data",
|
||||
example: r#""ATNAQ===" | decode base32hex"#,
|
||||
result: Some(Value::test_binary(vec![0x57, 0x6E, 0xAD])),
|
||||
},
|
||||
Example {
|
||||
description: "Decode an encoded string",
|
||||
example: r#""D1KG====" | decode base32hex | decode"#,
|
||||
result: Some(Value::test_string("hi")),
|
||||
},
|
||||
Example {
|
||||
description: "Parse a string without padding",
|
||||
example: r#""ATNAQ" | decode base32hex --nopad"#,
|
||||
result: Some(Value::test_binary(vec![0x57, 0x6E, 0xAD])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
@ -99,7 +115,23 @@ impl Command for EncodeBase32Hex {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Encode a binary value",
|
||||
example: r#"0x[57 6E AD] | encode base32hex"#,
|
||||
result: Some(Value::test_string("ATNAQ===")),
|
||||
},
|
||||
Example {
|
||||
description: "Encode a string",
|
||||
example: r#""hello there" | encode base32hex"#,
|
||||
result: Some(Value::test_string("D1IMOR3F41Q6GPBICK======")),
|
||||
},
|
||||
Example {
|
||||
description: "Don't apply padding to the output",
|
||||
example: r#""hello there" | encode base32hex"#,
|
||||
result: Some(Value::test_string("D1IMOR3F41Q6GPBICK")),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
|
|
@ -59,7 +59,23 @@ impl Command for DecodeBase64 {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Decode a Base64 string",
|
||||
example: r#""U29tZSBEYXRh" | decode base64 | decode"#,
|
||||
result: Some(Value::test_string("Some Data")),
|
||||
},
|
||||
Example {
|
||||
description: "Decode arbitrary data",
|
||||
example: r#""/w==" | decode base64"#,
|
||||
result: Some(Value::test_binary(vec![0xFF])),
|
||||
},
|
||||
Example {
|
||||
description: "Decode a URL-safe Base64 string",
|
||||
example: r#""_w==" | decode base64 --url"#,
|
||||
result: Some(Value::test_binary(vec![0xFF])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
@ -117,7 +133,23 @@ impl Command for EncodeBase64 {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Encode a string with Base64",
|
||||
example: r#""Alphabet from A to Z" | encode base64"#,
|
||||
result: Some(Value::test_string("Some Data")),
|
||||
},
|
||||
Example {
|
||||
description: "Encode arbitrary data",
|
||||
example: r#"0x[BE EE FF] | encode base64"#,
|
||||
result: Some(Value::test_string("vu7/")),
|
||||
},
|
||||
Example {
|
||||
description: "Use a URL-safe alphabet",
|
||||
example: r#"0x[BE EE FF] | encode base64 --url"#,
|
||||
result: Some(Value::test_string("vu7_")),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
|
|
@ -5,11 +5,11 @@ pub struct DecodeHex;
|
|||
|
||||
impl Command for DecodeHex {
|
||||
fn name(&self) -> &str {
|
||||
"decode base"
|
||||
"decode hex"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("decode base")
|
||||
Signature::build("decode hex")
|
||||
.input_output_types(vec![(Type::String, Type::Binary)])
|
||||
.allow_variants_without_examples(true)
|
||||
.category(Category::Formats)
|
||||
|
@ -20,7 +20,18 @@ impl Command for DecodeHex {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Decode arbitrary binary data",
|
||||
example: r#""09FD" | decode hex"#,
|
||||
result: Some(Value::test_binary(vec![0x09, 0xFD])),
|
||||
},
|
||||
Example {
|
||||
description: "Lowercase Hex is also accepted",
|
||||
example: r#""09fd" | decode hex"#,
|
||||
result: Some(Value::test_binary(vec![0x09, 0xFD])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
@ -71,7 +82,23 @@ impl Command for EncodeHex {
|
|||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![]
|
||||
vec![
|
||||
Example {
|
||||
description: "Encode a binary value",
|
||||
example: r#"0x[C3 06] | encode hex"#,
|
||||
result: Some(Value::test_string("C306")),
|
||||
},
|
||||
Example {
|
||||
description: "Encode a string",
|
||||
example: r#""hello" | encode hex"#,
|
||||
result: Some(Value::test_string("68656C6C6F")),
|
||||
},
|
||||
Example {
|
||||
description: "Output a Lowercase version of the encoding",
|
||||
example: r#"0x[AD EF] | encode hex --lower"#,
|
||||
result: Some(Value::test_string("adef")),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn is_const(&self) -> bool {
|
||||
|
|
Loading…
Reference in New Issue
Block a user