Add help tool
This commit is contained in:
parent
0a16edbc97
commit
478ccbb529
@ -150,7 +150,7 @@ fn run_cli_shell() {
|
||||
let eval_result = eval_with_context(line, &mut context);
|
||||
|
||||
match eval_result {
|
||||
Ok(_) => {}
|
||||
Ok(value) => println!("{value}"),
|
||||
Err(error) => eprintln!("{error}"),
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,37 @@ use std::{thread::sleep, time::Duration};
|
||||
|
||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||
|
||||
use crate::{Result, Tool, ToolInfo, Value, ValueType};
|
||||
use crate::{Result, Table, Tool, ToolInfo, Value, ValueType, TOOL_LIST};
|
||||
|
||||
pub struct Help;
|
||||
|
||||
impl Tool for Help {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "help",
|
||||
description: "Get help using dust.",
|
||||
group: "general",
|
||||
inputs: vec![ValueType::Empty, ValueType::String],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
self.check_type(argument)?;
|
||||
|
||||
let mut table = Table::new(vec!["tool".to_string(), "description".to_string()]);
|
||||
|
||||
for tool in TOOL_LIST {
|
||||
let row = vec![
|
||||
Value::String(tool.info().identifier.to_string()),
|
||||
Value::String(tool.info().description.to_string()),
|
||||
];
|
||||
|
||||
table.insert(row)?;
|
||||
}
|
||||
|
||||
Ok(Value::Table(table))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Output;
|
||||
|
||||
|
@ -50,7 +50,7 @@ pub mod time;
|
||||
/// Master list of all tools.
|
||||
///
|
||||
/// This list is used to match identifiers with tools and to provide info to the shell.
|
||||
pub const TOOL_LIST: [&'static dyn Tool; 51] = [
|
||||
pub const TOOL_LIST: [&'static dyn Tool; 52] = [
|
||||
&collections::Count,
|
||||
&collections::CreateTable,
|
||||
&collections::Insert,
|
||||
@ -82,6 +82,7 @@ pub const TOOL_LIST: [&'static dyn Tool; 51] = [
|
||||
&filesystem::Trash,
|
||||
&filesystem::Watch,
|
||||
&filesystem::Write,
|
||||
&general::Help,
|
||||
&general::Run,
|
||||
&general::Output,
|
||||
&general::Repeat,
|
||||
|
@ -38,11 +38,9 @@ impl PartialEq for ValueType {
|
||||
(ValueType::ListOf(_), ValueType::List) => true,
|
||||
(ValueType::List, ValueType::ListOf(_)) => true,
|
||||
(ValueType::ListOf(value_type), ValueType::ListExact(exact_list))
|
||||
| (ValueType::ListExact(exact_list), ValueType::ListOf(value_type)) => {
|
||||
exact_list
|
||||
.iter()
|
||||
.all(|exact_type| exact_type == value_type.as_ref())
|
||||
}
|
||||
| (ValueType::ListExact(exact_list), ValueType::ListOf(value_type)) => exact_list
|
||||
.iter()
|
||||
.all(|exact_type| exact_type == value_type.as_ref()),
|
||||
(ValueType::List, ValueType::List) => true,
|
||||
(ValueType::Empty, ValueType::Empty) => true,
|
||||
(ValueType::Map, ValueType::Map) => true,
|
||||
|
Loading…
Reference in New Issue
Block a user