diff --git a/src/commands/autoview.rs b/src/commands/autoview.rs index 844a093c4a..f970d23e4f 100644 --- a/src/commands/autoview.rs +++ b/src/commands/autoview.rs @@ -43,17 +43,36 @@ pub fn autoview( .. } = input[0usize] { - let binary = context.expect_command("binaryview"); - let result = binary.run(raw.with_input(input), &context.commands); - result.collect::>().await; + let binary = context.get_command("binaryview"); + if let Some(binary) = binary { + let result = binary.run(raw.with_input(input), &context.commands); + result.collect::>().await; + } else { + for i in input { + match i.item { + Value::Binary(b) => { + use pretty_hex::*; + println!("{:?}", b.hex_dump()); + } + _ => {} + } + } + }; } else if is_single_text_value(&input) { - let text = context.expect_command("textview"); - let result = text.run(raw.with_input(input), &context.commands); - result.collect::>().await; - } else if equal_shapes(&input) { - let table = context.expect_command("table"); - let result = table.run(raw.with_input(input), &context.commands); - result.collect::>().await; + let text = context.get_command("textview"); + if let Some(text) = text { + let result = text.run(raw.with_input(input), &context.commands); + result.collect::>().await; + } else { + for i in input { + match i.item { + Value::Primitive(Primitive::String(s)) => { + println!("{}", s); + } + _ => {} + } + } + } } else { let table = context.expect_command("table"); let result = table.run(raw.with_input(input), &context.commands); @@ -63,25 +82,6 @@ pub fn autoview( })) } -fn equal_shapes(input: &Vec>) -> bool { - let mut items = input.iter(); - - let item = match items.next() { - Some(item) => item, - None => return false, - }; - - let desc = item.data_descriptors(); - - for item in items { - if desc != item.data_descriptors() { - return false; - } - } - - true -} - fn is_single_text_value(input: &Vec>) -> bool { if input.len() != 1 { return false; diff --git a/src/commands/command.rs b/src/commands/command.rs index 9f4d256c2b..922f647fcc 100644 --- a/src/commands/command.rs +++ b/src/commands/command.rs @@ -236,6 +236,10 @@ impl RunnableContext { .get_command(name) .expect(&format!("Expected command {}", name)) } + + pub fn get_command(&self, name: &str) -> Option> { + self.commands.get_command(name) + } } pub struct RunnablePerItemArgs {