1
0

Clean up project; Rename commands to tools

This commit is contained in:
Jeff 2023-08-23 20:21:29 -04:00
parent 673616ac2a
commit 39d3ca85ea
20 changed files with 261 additions and 230 deletions

View File

@ -3,8 +3,8 @@
//! To deal with errors from dependencies, either create a new error variant
//! or use the MacroFailure variant if the error can only occur inside a macro.
use crate::{
operator::Operator, token::PartialToken, value::value_type::ValueType, value::Value, MacroInfo,
Node,
operator::Operator, token::PartialToken, value::value_type::ValueType, value::Value, Node,
ToolInfo,
};
use std::{fmt, io, time::SystemTimeError};
@ -133,7 +133,7 @@ pub enum Error {
/// A macro or function was called with the wrong type of input.
MacroArgumentType {
/// The macro that was called.
macro_info: MacroInfo<'static>,
macro_info: ToolInfo<'static>,
/// The actual value.
actual: Value,
},

View File

@ -5,7 +5,7 @@ use crate::{token, tree, Result, Value, VariableMap};
/// # Examples
///
/// ```rust
/// # use whale_lib::*;
/// # use dust_lib::*;
/// assert_eq!(eval("1 + 2 + 3"), Ok(Value::from(6)));
/// ```
///
@ -20,12 +20,12 @@ pub fn eval(string: &str) -> Result<Value> {
/// # Examples
///
/// ```rust
/// # use whale_lib::*;
/// # use dust_lib::*;
/// let mut context = VariableMap::new();
/// context.set_value("one".into(), 1.into()).unwrap(); // Do proper error handling here
/// context.set_value("two".into(), 2.into()).unwrap(); // Do proper error handling here
/// context.set_value("three".into(), 3.into()).unwrap(); // Do proper error handling here
/// assert_eq!(eval_with_context("one + two + three", &context), Ok(Value::from(6)));
/// assert_eq!(eval_with_context("one + two + three", &mut context), Ok(Value::from(6)));
/// ```
///
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.*

View File

@ -2,11 +2,11 @@
#![forbid(unsafe_code)]
pub use crate::{
commands::*,
error::*,
interface::*,
operator::Operator,
token::PartialToken,
tools::{Tool, ToolInfo, TOOL_LIST},
tree::Node,
value::{
function::Function, table::Table, time::Time, value_type::ValueType,
@ -14,7 +14,8 @@ pub use crate::{
},
};
mod commands;
pub mod tools;
mod error;
mod interface;
mod operator;

View File

@ -13,8 +13,8 @@ use std::{
path::PathBuf,
};
use whale_lib::{
eval, eval_with_context, gui::GuiApp, Macro, MacroInfo, Result, Value, VariableMap, MACRO_LIST,
use dust_lib::{
eval, eval_with_context, gui::GuiApp, Result, Tool, ToolInfo, Value, VariableMap, TOOL_LIST,
};
/// Command-line arguments to be parsed.
@ -113,11 +113,11 @@ impl WhaleCompeleter {
}
}
pub fn set_macro_list(&mut self, macro_list: Vec<&'static dyn Macro>) -> &mut Self {
pub fn set_command_list(&mut self, macro_list: Vec<&'static dyn Tool>) -> &mut Self {
self.macro_list = macro_list
.iter()
.map(|r#macro| {
let MacroInfo {
let ToolInfo {
identifier,
description,
group,
@ -204,7 +204,7 @@ impl Completer for WhaleCompeleter {
fn setup_reedline() -> Reedline {
let mut completer = Box::new(WhaleCompeleter::new());
completer.set_macro_list(MACRO_LIST.to_vec());
completer.set_command_list(TOOL_LIST.to_vec());
let completion_menu = Box::new(
ColumnarMenu::default()

View File

@ -1,12 +1,12 @@
//! Macros for collection values: strings, lists, maps and tables.
use crate::{Error, Macro, MacroInfo, Result, Table, Value, ValueType, VariableMap};
use crate::{Error, Result, Table, Tool, ToolInfo, Value, ValueType, VariableMap};
pub struct Transform;
impl Macro for Transform {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Transform {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "transform",
description: "Alter a collection by calling a function on each value.",
group: "collections",
@ -53,9 +53,9 @@ impl Macro for Transform {
pub struct String;
impl Macro for String {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for String {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "string",
description: "Stringify a value.",
group: "collections",
@ -83,9 +83,9 @@ impl Macro for String {
pub struct Count;
impl Macro for Count {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Count {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "count",
description: "Return the number of items in a value.",
group: "collections",
@ -113,9 +113,9 @@ impl Macro for Count {
pub struct CreateTable;
impl Macro for CreateTable {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for CreateTable {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "create_table",
description: "Define a new table with a list of column names and list of rows.",
group: "collections",
@ -149,9 +149,9 @@ impl Macro for CreateTable {
pub struct Rows;
impl Macro for Rows {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Rows {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "rows",
description: "Extract a table's rows as a list.",
group: "collections",
@ -174,9 +174,9 @@ impl Macro for Rows {
pub struct Get;
impl Macro for Get {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Get {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "get",
description: "Retrieve a value from a collection.",
group: "collections",
@ -207,9 +207,9 @@ impl Macro for Get {
pub struct Insert;
impl Macro for Insert {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Insert {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "insert",
description: "Add new rows to a table.",
group: "collections",
@ -236,9 +236,9 @@ impl Macro for Insert {
pub struct Select;
impl Macro for Select {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Select {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "select",
description: "Extract one or more values based on their key.",
group: "collections",
@ -305,9 +305,9 @@ impl Macro for Select {
pub struct ForEach;
impl Macro for ForEach {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for ForEach {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "for_each",
description: "Run an operation on every item in a collection.",
group: "collections",
@ -342,9 +342,9 @@ impl Macro for ForEach {
pub struct Where;
impl Macro for Where {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Where {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "where",
description: "Keep rows matching a predicate.",
group: "collections",

View File

@ -1,12 +1,12 @@
use std::process::Command;
use crate::{Macro, MacroInfo, Result, Value};
use crate::{Result, Tool, ToolInfo, Value};
pub struct Sh;
impl Macro for Sh {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Sh {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "sh",
description: "Pass input to the Bourne Shell.",
group: "command",
@ -25,9 +25,9 @@ impl Macro for Sh {
pub struct Bash;
impl Macro for Bash {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Bash {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "bash",
description: "Pass input to the Bourne Again Shell.",
group: "command",
@ -49,9 +49,9 @@ impl Macro for Bash {
}
pub struct Fish;
impl Macro for Fish {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Fish {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "fish",
description: "Pass input to the fish shell.",
group: "command",
@ -74,9 +74,9 @@ impl Macro for Fish {
pub struct Zsh;
impl Macro for Zsh {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Zsh {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "zsh",
description: "Pass input to the Z shell.",
group: "command",
@ -99,9 +99,9 @@ impl Macro for Zsh {
pub struct Raw;
impl Macro for Raw {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Raw {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "raw",
description: "Run input as a command without a shell",
group: "command",

View File

@ -1,12 +1,12 @@
//! Convert values to and from data formats like JSON and TOML.
use crate::{Macro, MacroInfo, Result, Table, Value, ValueType};
use crate::{Result, Table, Tool, ToolInfo, Value, ValueType};
pub struct FromJson;
impl Macro for FromJson {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for FromJson {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "from_json",
description: "Get a whale value from a JSON string.",
group: "data",
@ -24,9 +24,9 @@ impl Macro for FromJson {
pub struct ToJson;
impl Macro for ToJson {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for ToJson {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "to_json",
description: "Create a JSON string from a whale value.",
group: "data",
@ -43,9 +43,9 @@ impl Macro for ToJson {
pub struct FromCsv;
impl Macro for FromCsv {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for FromCsv {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "from_csv",
description: "Create a whale value from a CSV string.",
group: "data",
@ -90,9 +90,9 @@ impl Macro for FromCsv {
pub struct ToCsv;
impl Macro for ToCsv {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for ToCsv {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "to_csv",
description: "Convert a value to a string of comma-separated values.",
group: "data",

View File

@ -2,13 +2,13 @@ use std::process::Command;
use sysinfo::{DiskExt, System, SystemExt};
use crate::{Macro, MacroInfo, Result, Table, Value};
use crate::{Result, Table, Tool, ToolInfo, Value};
pub struct ListDisks;
impl Macro for ListDisks {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for ListDisks {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "list_disks",
description: "List all block devices.",
group: "disks",
@ -60,9 +60,9 @@ impl Macro for ListDisks {
pub struct Partition;
impl Macro for Partition {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Partition {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "partition",
description: "Partition a disk, clearing its content.",
group: "disks",

View File

@ -1,22 +1,24 @@
//! Tools for files and directories.
//! Dust commands for managing files and directories.
use std::{
fs::{self, OpenOptions},
io::{Read, Write as IoWrite},
path::PathBuf,
};
use crate::{Error, Macro, MacroInfo, Result, Table, Time, Value, ValueType};
use crate::{Error, Result, Table, Time, Tool, ToolInfo, Value, ValueType};
pub struct Append;
impl Macro for Append {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Append {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "append",
description: "Append data to a file.",
group: "filesystem",
inputs: vec![],
inputs: vec![ValueType::ListExact(vec![
ValueType::String,
ValueType::Any,
])],
}
}
@ -34,13 +36,16 @@ impl Macro for Append {
pub struct CreateDir;
impl Macro for CreateDir {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for CreateDir {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "create_dir",
description: "Create one or more directories.",
group: "filesystem",
inputs: vec![],
inputs: vec![
ValueType::String,
ValueType::ListOf(Box::new(ValueType::String)),
],
}
}
@ -54,13 +59,16 @@ impl Macro for CreateDir {
pub struct FileMetadata;
impl Macro for FileMetadata {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for FileMetadata {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "file_metadata",
description: "Get metadata for files.",
group: "filesystem",
inputs: vec![],
inputs: vec![
ValueType::String,
ValueType::ListOf(Box::new(ValueType::String)),
],
}
}
@ -97,9 +105,9 @@ impl Macro for FileMetadata {
pub struct ReadDir;
impl Macro for ReadDir {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for ReadDir {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "read_dir",
description: "Read the content of a directory.",
group: "filesystem",
@ -168,9 +176,9 @@ impl Macro for ReadDir {
pub struct ReadFile;
impl Macro for ReadFile {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for ReadFile {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "read_file",
description: "Read file contents.",
group: "filesystem",
@ -194,13 +202,16 @@ impl Macro for ReadFile {
pub struct RemoveDir;
impl Macro for RemoveDir {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for RemoveDir {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "remove_dir",
description: "Remove directories.",
group: "filesystem",
inputs: vec![],
inputs: vec![
ValueType::String,
ValueType::ListOf(Box::new(ValueType::String)),
],
}
}
@ -214,13 +225,16 @@ impl Macro for RemoveDir {
pub struct MoveDir;
impl Macro for MoveDir {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for MoveDir {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "move_dir",
description: "Move a directory to a new path.",
group: "filesystem",
inputs: vec![],
inputs: vec![ValueType::ListExact(vec![
ValueType::String,
ValueType::String,
])],
}
}
@ -252,13 +266,16 @@ impl Macro for MoveDir {
pub struct Trash;
impl Macro for Trash {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Trash {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "trash",
description: "Move a file or directory to the trash.",
group: "filesystem",
inputs: vec![],
inputs: vec![
ValueType::String,
ValueType::ListOf(Box::new(ValueType::String)),
],
}
}
@ -273,13 +290,16 @@ impl Macro for Trash {
pub struct Write;
impl Macro for Write {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Write {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "write",
description: "Write data to a file.",
group: "filesystem",
inputs: vec![],
inputs: vec![ValueType::ListExact(vec![
ValueType::String,
ValueType::Any,
])],
}
}
@ -307,9 +327,9 @@ impl Macro for Write {
pub struct RemoveFile;
impl Macro for RemoveFile {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for RemoveFile {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "remove_file",
description: "Permanently delete a file.",
group: "filesystem",
@ -343,13 +363,13 @@ impl Macro for RemoveFile {
pub struct Watch;
impl Macro for Watch {
fn info(&self) -> crate::MacroInfo<'static> {
crate::MacroInfo {
impl Tool for Watch {
fn info(&self) -> crate::ToolInfo<'static> {
crate::ToolInfo {
identifier: "watch",
description: "Wait until a file changes.",
group: "filesystem",
inputs: vec![],
inputs: vec![ValueType::String],
}
}

View File

@ -2,13 +2,13 @@ use std::{fs, thread::sleep, time::Duration};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use crate::{Function, Macro, MacroInfo, Result, Value};
use crate::{Function, Result, Tool, ToolInfo, Value};
pub struct Output;
impl Macro for Output {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Output {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "output",
description: "Print a value.",
group: "general",
@ -24,9 +24,9 @@ impl Macro for Output {
}
pub struct Repeat;
impl Macro for Repeat {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Repeat {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "repeat",
description: "Run a function the given number of times.",
group: "general",
@ -52,9 +52,9 @@ impl Macro for Repeat {
pub struct Run;
impl Macro for Run {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Run {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "run",
description: "Run a whale file.",
group: "general",
@ -72,9 +72,9 @@ impl Macro for Run {
pub struct Async;
impl Macro for Async {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Async {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "async",
description: "Run functions in parallel.",
group: "general",
@ -106,9 +106,9 @@ impl Macro for Async {
pub struct Wait;
impl Macro for Wait {
fn info(&self) -> crate::MacroInfo<'static> {
MacroInfo {
impl Tool for Wait {
fn info(&self) -> crate::ToolInfo<'static> {
ToolInfo {
identifier: "wait",
description: "Wait for the given number of milliseconds.",
group: "general",

View File

@ -9,13 +9,13 @@ use eframe::{
};
use egui_extras::{Column, StripBuilder, TableBuilder};
use crate::{eval_with_context, Error, Macro, MacroInfo, Result, Table, Value, VariableMap};
use crate::{eval_with_context, Error, Result, Table, Tool, ToolInfo, Value, VariableMap};
pub struct CreateLine;
impl Macro for CreateLine {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for CreateLine {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "create_line",
description: "Create a map value to be shown as a line in a plot.",
group: "gui",
@ -40,9 +40,9 @@ impl Macro for CreateLine {
pub struct BarGraph;
impl Macro for BarGraph {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for BarGraph {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "bar_graph",
description: "Render a list of values as a bar graph.",
group: "gui",
@ -125,9 +125,9 @@ impl eframe::App for BarGraphGui {
pub struct Plot;
impl Macro for Plot {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Plot {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "plot",
description: "Render a list of numbers as a scatter plot graph.",
group: "gui",
@ -193,9 +193,9 @@ impl eframe::App for PlotGui {
pub struct Gui;
impl Macro for Gui {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Gui {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "gui",
description: "Display a value in a GUI window.",
group: "gui",

View File

@ -1,11 +1,11 @@
use crate::{Error, Macro, MacroInfo, Result, Value, ValueType };
use crate::{Error, Tool, ToolInfo, Result, Value, ValueType };
pub struct Assert;
impl Macro for Assert {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Assert {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "assert",
description: "Panic if a boolean is false.",
group: "test",
@ -30,9 +30,9 @@ impl Macro for Assert {
pub struct AssertEqual;
impl Macro for AssertEqual {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for AssertEqual {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "assert_equal",
description: "Panic if two values do not match.",
group: "test",
@ -54,9 +54,9 @@ impl Macro for AssertEqual {
pub struct If;
impl Macro for If {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for If {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "if",
description: "Evaluates the first argument. If true, it does the second argument.",
group: "logic",
@ -92,9 +92,9 @@ impl Macro for If {
pub struct IfElse;
impl Macro for IfElse {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for IfElse {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "if_else",
description: "Evaluates the first argument. If true, it does the second argument. If false, it does the third argument",
group: "logic",
@ -139,9 +139,9 @@ impl Macro for IfElse {
pub struct Loop;
impl Macro for Loop {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Loop {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "loop",
description: "Repeats a function until the program ends.",
group: "general",

View File

@ -2,17 +2,27 @@
//!
//! ## Writing macros
//!
//! - snake case identifier, this is enforced by a test
//! - the description should be brief, it will display in the shell
//!
//! - Snake case identifier, this is enforced by a test
//! - The description should be brief, it will display in the shell
//! - Recycle code that is already written and tested
//! - Write non-trivial tests, do not write tests just for the sake of writing them
//!
//! ## Usage
//!
//! Macros can be used in Rust by passing a Value to the run method.
//! Commands can be used in Rust by passing a Value to the run method.
//!
//! ```
//! let value = Value::List(vec![1, 2,3]);
//! let count = Count.run(value).as_string().unwrap();
//! # use dust_lib::{tools::collections::Count, Tool, Value};
//! let value = Value::List(vec![
//! Value::Integer(1),
//! Value::Integer(2),
//! Value::Integer(3),
//! ]);
//! let count = Count
//! .run(&value)
//! .unwrap()
//! .as_int()
//! .unwrap();
//!
//! assert_eq!(count, 3);
//! ```
@ -37,7 +47,7 @@ pub mod time;
///
/// This list is used to match identifiers with macros and to provide info to
/// the shell.
pub const MACRO_LIST: [&'static dyn Macro; 57] = [
pub const TOOL_LIST: [&'static dyn Tool; 57] = [
&collections::Count,
&collections::CreateTable,
&collections::Get,
@ -98,14 +108,14 @@ pub const MACRO_LIST: [&'static dyn Macro; 57] = [
];
/// A whale macro function.
pub trait Macro: Sync + Send {
fn info(&self) -> MacroInfo<'static>;
pub trait Tool: Sync + Send {
fn info(&self) -> ToolInfo<'static>;
fn run(&self, argument: &Value) -> Result<Value>;
}
/// Information needed for each macro.
#[derive(Clone, Debug, PartialEq)]
pub struct MacroInfo<'a> {
pub struct ToolInfo<'a> {
/// Text pattern that triggers this macro.
pub identifier: &'a str,
@ -350,7 +360,7 @@ mod tests {
#[test]
fn macro_formatting() {
for function in MACRO_LIST {
for function in TOOL_LIST {
let identifier = function.info().identifier;
assert_eq!(identifier.to_lowercase(), identifier);

View File

@ -1,12 +1,12 @@
//! Macros for network access.
use crate::{Macro, MacroInfo, Result, Value};
use crate::{Result, Tool, ToolInfo, Value};
pub struct Download;
impl Macro for Download {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Download {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "download",
description: "Fetch a network resource.",
group: "network",

View File

@ -1,12 +1,12 @@
use std::process::Command;
use crate::{Error, Macro, MacroInfo, Result, Value};
use crate::{Error, Result, Tool, ToolInfo, Value};
pub struct CoprRepositories;
impl Macro for CoprRepositories {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for CoprRepositories {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "enable_copr_repository",
description: "Enable one or more COPR repositories.",
group: "package management",
@ -37,9 +37,9 @@ impl Macro for CoprRepositories {
pub struct InstallPackage;
impl Macro for InstallPackage {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for InstallPackage {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "install_package",
description: "Install one or more packages.",
group: "package management",
@ -73,9 +73,9 @@ impl Macro for InstallPackage {
pub struct EnableRpmRepositories;
impl Macro for EnableRpmRepositories {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for EnableRpmRepositories {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "enable_rpm_repositories",
description: "Enable one or more RPM repositories.",
group: "package management",
@ -110,9 +110,9 @@ impl Macro for EnableRpmRepositories {
pub struct UninstallPackage;
impl Macro for UninstallPackage {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for UninstallPackage {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "uninstall_package",
description: "Uninstall one or more packages.",
group: "package management",
@ -146,9 +146,9 @@ impl Macro for UninstallPackage {
pub struct UpgradePackages;
impl Macro for UpgradePackages {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for UpgradePackages {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "upgrade_packages",
description: "Upgrade all installed packages.",
group: "package management",

View File

@ -2,13 +2,13 @@ use std::convert::TryInto;
use rand::{random, thread_rng, Rng};
use crate::{Error, Macro, MacroInfo, Result, Value};
use crate::{Error, Result, Tool, ToolInfo, Value};
pub struct RandomBoolean;
impl Macro for RandomBoolean {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for RandomBoolean {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "random_boolean",
description: "Create a random boolean.",
group: "random",
@ -27,9 +27,9 @@ impl Macro for RandomBoolean {
pub struct RandomInteger;
impl Macro for RandomInteger {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for RandomInteger {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "random_integer",
description: "Create a random integer.",
group: "random",
@ -61,9 +61,9 @@ impl Macro for RandomInteger {
pub struct RandomString;
impl Macro for RandomString {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for RandomString {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "random_string",
description: "Generate a random string.",
group: "random",
@ -105,9 +105,9 @@ impl Macro for RandomString {
pub struct RandomFloat;
impl Macro for RandomFloat {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for RandomFloat {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "random_float",
description: "Generate a random floating point value between 0 and 1.",
group: "random",
@ -124,9 +124,9 @@ impl Macro for RandomFloat {
pub struct Random;
impl Macro for Random {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Random {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "random",
description: "Select a random item from a collection.",
group: "random",

View File

@ -1,12 +1,12 @@
use sys_info::cpu_speed;
use crate::{Macro, MacroInfo, Result, Value};
use crate::{Result, Tool, ToolInfo, Value};
pub struct CpuSpeed;
impl Macro for CpuSpeed {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for CpuSpeed {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "cpu_speed",
description: "Return the current processor speed in megahertz.",
group: "system",

View File

@ -1,12 +1,12 @@
use std::time::Instant;
use crate::{Macro, MacroInfo, Result, Time, Value};
use crate::{Result, Time, Tool, ToolInfo, Value};
pub struct Now;
impl Macro for Now {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Now {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "now",
description: "Return the current time.",
group: "time",
@ -25,9 +25,9 @@ impl Macro for Now {
pub struct Local;
impl Macro for Local {
fn info(&self) -> MacroInfo<'static> {
MacroInfo {
impl Tool for Local {
fn info(&self) -> ToolInfo<'static> {
ToolInfo {
identifier: "local",
description: "Show a time value adjusted for the current time zone.",
group: "time",

View File

@ -4,7 +4,7 @@ use std::{
fmt::{self, Display, Formatter},
};
use crate::{value::Value, Error, Result, Table, MACRO_LIST};
use crate::{value::Value, Error, Result, Table, TOOL_LIST};
/// A context that stores its mappings in hash maps.
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
@ -21,7 +21,7 @@ impl VariableMap {
}
pub fn call_function(&self, identifier: &str, argument: &Value) -> Result<Value> {
for macro_item in MACRO_LIST {
for macro_item in TOOL_LIST {
let valid_input_types = macro_item.info().inputs;
if identifier == macro_item.info().identifier {

View File

@ -1,6 +1,6 @@
use std::fs::read_to_string;
use whale_lib::*;
use dust_lib::*;
#[test]
fn collections() {