Stefan Holderbach b2e191f836
Remove Signature.vectorizes_over_list entirely (#9777)
# Description
With the current typechecking logic this property has no effect.
It was only used in the example testing, and provided some indication of
this vectorizing property.
With #9742 all commands that previously declared it have explicit list
signatures. If we want to get it back in the future we can reconstruct
it from the signature.

Simplifies the example testing a bit.

# User-Facing Changes
Causes a breaking change for plugins that previously declared it. While
this causes a compile fail, this was already broken by our more
stringent type checking.
This will be a good reminder for plugin authors to update their
signature as well to reflect the more stringent type checking.
2023-07-26 23:34:43 +02:00

81 lines
2.2 KiB
Rust

use super::hex::{operate, ActionType};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
#[derive(Clone)]
pub struct DecodeHex;
impl Command for DecodeHex {
fn name(&self) -> &str {
"decode hex"
}
fn signature(&self) -> Signature {
Signature::build("decode hex")
.input_output_types(vec![
(Type::String, Type::Binary),
(
Type::List(Box::new(Type::String)),
Type::List(Box::new(Type::Binary)),
),
(Type::Table(vec![]), Type::Table(vec![])),
(Type::Record(vec![]), Type::Record(vec![])),
])
.allow_variants_without_examples(true)
.rest(
"rest",
SyntaxShape::CellPath,
"For a data structure input, decode data at the given cell paths",
)
.category(Category::Formats)
}
fn usage(&self) -> &str {
"Hex decode a value."
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Hex decode a value and output as binary",
example: "'0102030A0a0B' | decode hex",
result: Some(Value::binary(
[0x01, 0x02, 0x03, 0x0A, 0x0A, 0x0B],
Span::test_data(),
)),
},
Example {
description: "Whitespaces are allowed to be between hex digits",
example: "'01 02 03 0A 0a 0B' | decode hex",
result: Some(Value::binary(
[0x01, 0x02, 0x03, 0x0A, 0x0A, 0x0B],
Span::test_data(),
)),
},
]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
operate(ActionType::Decode, engine_state, stack, call, input)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_examples() {
crate::test_examples(DecodeHex)
}
}