Clean up project; Rename commands to tools
This commit is contained in:
parent
673616ac2a
commit
39d3ca85ea
@ -3,8 +3,8 @@
|
|||||||
//! To deal with errors from dependencies, either create a new error variant
|
//! 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.
|
//! or use the MacroFailure variant if the error can only occur inside a macro.
|
||||||
use crate::{
|
use crate::{
|
||||||
operator::Operator, token::PartialToken, value::value_type::ValueType, value::Value, MacroInfo,
|
operator::Operator, token::PartialToken, value::value_type::ValueType, value::Value, Node,
|
||||||
Node,
|
ToolInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{fmt, io, time::SystemTimeError};
|
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.
|
/// A macro or function was called with the wrong type of input.
|
||||||
MacroArgumentType {
|
MacroArgumentType {
|
||||||
/// The macro that was called.
|
/// The macro that was called.
|
||||||
macro_info: MacroInfo<'static>,
|
macro_info: ToolInfo<'static>,
|
||||||
/// The actual value.
|
/// The actual value.
|
||||||
actual: Value,
|
actual: Value,
|
||||||
},
|
},
|
||||||
|
@ -5,7 +5,7 @@ use crate::{token, tree, Result, Value, VariableMap};
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use whale_lib::*;
|
/// # use dust_lib::*;
|
||||||
/// assert_eq!(eval("1 + 2 + 3"), Ok(Value::from(6)));
|
/// assert_eq!(eval("1 + 2 + 3"), Ok(Value::from(6)));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
@ -20,12 +20,12 @@ pub fn eval(string: &str) -> Result<Value> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use whale_lib::*;
|
/// # use dust_lib::*;
|
||||||
/// let mut context = VariableMap::new();
|
/// let mut context = VariableMap::new();
|
||||||
/// context.set_value("one".into(), 1.into()).unwrap(); // Do proper error handling here
|
/// 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("two".into(), 2.into()).unwrap(); // Do proper error handling here
|
||||||
/// context.set_value("three".into(), 3.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.*
|
/// *See the [crate doc](index.html) for more examples and explanations of the expression format.*
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
commands::*,
|
|
||||||
error::*,
|
error::*,
|
||||||
interface::*,
|
interface::*,
|
||||||
operator::Operator,
|
operator::Operator,
|
||||||
token::PartialToken,
|
token::PartialToken,
|
||||||
|
tools::{Tool, ToolInfo, TOOL_LIST},
|
||||||
tree::Node,
|
tree::Node,
|
||||||
value::{
|
value::{
|
||||||
function::Function, table::Table, time::Time, value_type::ValueType,
|
function::Function, table::Table, time::Time, value_type::ValueType,
|
||||||
@ -14,7 +14,8 @@ pub use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod commands;
|
pub mod tools;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
mod interface;
|
mod interface;
|
||||||
mod operator;
|
mod operator;
|
||||||
|
10
src/main.rs
10
src/main.rs
@ -13,8 +13,8 @@ use std::{
|
|||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
use whale_lib::{
|
use dust_lib::{
|
||||||
eval, eval_with_context, gui::GuiApp, Macro, MacroInfo, Result, Value, VariableMap, MACRO_LIST,
|
eval, eval_with_context, gui::GuiApp, Result, Tool, ToolInfo, Value, VariableMap, TOOL_LIST,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Command-line arguments to be parsed.
|
/// 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
|
self.macro_list = macro_list
|
||||||
.iter()
|
.iter()
|
||||||
.map(|r#macro| {
|
.map(|r#macro| {
|
||||||
let MacroInfo {
|
let ToolInfo {
|
||||||
identifier,
|
identifier,
|
||||||
description,
|
description,
|
||||||
group,
|
group,
|
||||||
@ -204,7 +204,7 @@ impl Completer for WhaleCompeleter {
|
|||||||
fn setup_reedline() -> Reedline {
|
fn setup_reedline() -> Reedline {
|
||||||
let mut completer = Box::new(WhaleCompeleter::new());
|
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(
|
let completion_menu = Box::new(
|
||||||
ColumnarMenu::default()
|
ColumnarMenu::default()
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
//! Macros for collection values: strings, lists, maps and tables.
|
//! 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;
|
pub struct Transform;
|
||||||
|
|
||||||
impl Macro for Transform {
|
impl Tool for Transform {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "transform",
|
identifier: "transform",
|
||||||
description: "Alter a collection by calling a function on each value.",
|
description: "Alter a collection by calling a function on each value.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -53,9 +53,9 @@ impl Macro for Transform {
|
|||||||
|
|
||||||
pub struct String;
|
pub struct String;
|
||||||
|
|
||||||
impl Macro for String {
|
impl Tool for String {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "string",
|
identifier: "string",
|
||||||
description: "Stringify a value.",
|
description: "Stringify a value.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -83,9 +83,9 @@ impl Macro for String {
|
|||||||
|
|
||||||
pub struct Count;
|
pub struct Count;
|
||||||
|
|
||||||
impl Macro for Count {
|
impl Tool for Count {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "count",
|
identifier: "count",
|
||||||
description: "Return the number of items in a value.",
|
description: "Return the number of items in a value.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -113,9 +113,9 @@ impl Macro for Count {
|
|||||||
|
|
||||||
pub struct CreateTable;
|
pub struct CreateTable;
|
||||||
|
|
||||||
impl Macro for CreateTable {
|
impl Tool for CreateTable {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "create_table",
|
identifier: "create_table",
|
||||||
description: "Define a new table with a list of column names and list of rows.",
|
description: "Define a new table with a list of column names and list of rows.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -149,9 +149,9 @@ impl Macro for CreateTable {
|
|||||||
|
|
||||||
pub struct Rows;
|
pub struct Rows;
|
||||||
|
|
||||||
impl Macro for Rows {
|
impl Tool for Rows {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "rows",
|
identifier: "rows",
|
||||||
description: "Extract a table's rows as a list.",
|
description: "Extract a table's rows as a list.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -174,9 +174,9 @@ impl Macro for Rows {
|
|||||||
|
|
||||||
pub struct Get;
|
pub struct Get;
|
||||||
|
|
||||||
impl Macro for Get {
|
impl Tool for Get {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "get",
|
identifier: "get",
|
||||||
description: "Retrieve a value from a collection.",
|
description: "Retrieve a value from a collection.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -207,9 +207,9 @@ impl Macro for Get {
|
|||||||
|
|
||||||
pub struct Insert;
|
pub struct Insert;
|
||||||
|
|
||||||
impl Macro for Insert {
|
impl Tool for Insert {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "insert",
|
identifier: "insert",
|
||||||
description: "Add new rows to a table.",
|
description: "Add new rows to a table.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -236,9 +236,9 @@ impl Macro for Insert {
|
|||||||
|
|
||||||
pub struct Select;
|
pub struct Select;
|
||||||
|
|
||||||
impl Macro for Select {
|
impl Tool for Select {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "select",
|
identifier: "select",
|
||||||
description: "Extract one or more values based on their key.",
|
description: "Extract one or more values based on their key.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -305,9 +305,9 @@ impl Macro for Select {
|
|||||||
|
|
||||||
pub struct ForEach;
|
pub struct ForEach;
|
||||||
|
|
||||||
impl Macro for ForEach {
|
impl Tool for ForEach {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "for_each",
|
identifier: "for_each",
|
||||||
description: "Run an operation on every item in a collection.",
|
description: "Run an operation on every item in a collection.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
@ -342,9 +342,9 @@ impl Macro for ForEach {
|
|||||||
|
|
||||||
pub struct Where;
|
pub struct Where;
|
||||||
|
|
||||||
impl Macro for Where {
|
impl Tool for Where {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "where",
|
identifier: "where",
|
||||||
description: "Keep rows matching a predicate.",
|
description: "Keep rows matching a predicate.",
|
||||||
group: "collections",
|
group: "collections",
|
@ -1,12 +1,12 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::{Macro, MacroInfo, Result, Value};
|
use crate::{Result, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct Sh;
|
pub struct Sh;
|
||||||
|
|
||||||
impl Macro for Sh {
|
impl Tool for Sh {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "sh",
|
identifier: "sh",
|
||||||
description: "Pass input to the Bourne Shell.",
|
description: "Pass input to the Bourne Shell.",
|
||||||
group: "command",
|
group: "command",
|
||||||
@ -25,9 +25,9 @@ impl Macro for Sh {
|
|||||||
|
|
||||||
pub struct Bash;
|
pub struct Bash;
|
||||||
|
|
||||||
impl Macro for Bash {
|
impl Tool for Bash {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "bash",
|
identifier: "bash",
|
||||||
description: "Pass input to the Bourne Again Shell.",
|
description: "Pass input to the Bourne Again Shell.",
|
||||||
group: "command",
|
group: "command",
|
||||||
@ -49,9 +49,9 @@ impl Macro for Bash {
|
|||||||
}
|
}
|
||||||
pub struct Fish;
|
pub struct Fish;
|
||||||
|
|
||||||
impl Macro for Fish {
|
impl Tool for Fish {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "fish",
|
identifier: "fish",
|
||||||
description: "Pass input to the fish shell.",
|
description: "Pass input to the fish shell.",
|
||||||
group: "command",
|
group: "command",
|
||||||
@ -74,9 +74,9 @@ impl Macro for Fish {
|
|||||||
|
|
||||||
pub struct Zsh;
|
pub struct Zsh;
|
||||||
|
|
||||||
impl Macro for Zsh {
|
impl Tool for Zsh {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "zsh",
|
identifier: "zsh",
|
||||||
description: "Pass input to the Z shell.",
|
description: "Pass input to the Z shell.",
|
||||||
group: "command",
|
group: "command",
|
||||||
@ -99,9 +99,9 @@ impl Macro for Zsh {
|
|||||||
|
|
||||||
pub struct Raw;
|
pub struct Raw;
|
||||||
|
|
||||||
impl Macro for Raw {
|
impl Tool for Raw {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "raw",
|
identifier: "raw",
|
||||||
description: "Run input as a command without a shell",
|
description: "Run input as a command without a shell",
|
||||||
group: "command",
|
group: "command",
|
@ -1,12 +1,12 @@
|
|||||||
//! Convert values to and from data formats like JSON and TOML.
|
//! 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;
|
pub struct FromJson;
|
||||||
|
|
||||||
impl Macro for FromJson {
|
impl Tool for FromJson {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "from_json",
|
identifier: "from_json",
|
||||||
description: "Get a whale value from a JSON string.",
|
description: "Get a whale value from a JSON string.",
|
||||||
group: "data",
|
group: "data",
|
||||||
@ -24,9 +24,9 @@ impl Macro for FromJson {
|
|||||||
|
|
||||||
pub struct ToJson;
|
pub struct ToJson;
|
||||||
|
|
||||||
impl Macro for ToJson {
|
impl Tool for ToJson {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "to_json",
|
identifier: "to_json",
|
||||||
description: "Create a JSON string from a whale value.",
|
description: "Create a JSON string from a whale value.",
|
||||||
group: "data",
|
group: "data",
|
||||||
@ -43,9 +43,9 @@ impl Macro for ToJson {
|
|||||||
|
|
||||||
pub struct FromCsv;
|
pub struct FromCsv;
|
||||||
|
|
||||||
impl Macro for FromCsv {
|
impl Tool for FromCsv {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "from_csv",
|
identifier: "from_csv",
|
||||||
description: "Create a whale value from a CSV string.",
|
description: "Create a whale value from a CSV string.",
|
||||||
group: "data",
|
group: "data",
|
||||||
@ -90,9 +90,9 @@ impl Macro for FromCsv {
|
|||||||
|
|
||||||
pub struct ToCsv;
|
pub struct ToCsv;
|
||||||
|
|
||||||
impl Macro for ToCsv {
|
impl Tool for ToCsv {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "to_csv",
|
identifier: "to_csv",
|
||||||
description: "Convert a value to a string of comma-separated values.",
|
description: "Convert a value to a string of comma-separated values.",
|
||||||
group: "data",
|
group: "data",
|
@ -2,13 +2,13 @@ use std::process::Command;
|
|||||||
|
|
||||||
use sysinfo::{DiskExt, System, SystemExt};
|
use sysinfo::{DiskExt, System, SystemExt};
|
||||||
|
|
||||||
use crate::{Macro, MacroInfo, Result, Table, Value};
|
use crate::{Result, Table, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct ListDisks;
|
pub struct ListDisks;
|
||||||
|
|
||||||
impl Macro for ListDisks {
|
impl Tool for ListDisks {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "list_disks",
|
identifier: "list_disks",
|
||||||
description: "List all block devices.",
|
description: "List all block devices.",
|
||||||
group: "disks",
|
group: "disks",
|
||||||
@ -60,9 +60,9 @@ impl Macro for ListDisks {
|
|||||||
|
|
||||||
pub struct Partition;
|
pub struct Partition;
|
||||||
|
|
||||||
impl Macro for Partition {
|
impl Tool for Partition {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "partition",
|
identifier: "partition",
|
||||||
description: "Partition a disk, clearing its content.",
|
description: "Partition a disk, clearing its content.",
|
||||||
group: "disks",
|
group: "disks",
|
@ -1,22 +1,24 @@
|
|||||||
//! Tools for files and directories.
|
//! Dust commands for managing files and directories.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, OpenOptions},
|
fs::{self, OpenOptions},
|
||||||
io::{Read, Write as IoWrite},
|
io::{Read, Write as IoWrite},
|
||||||
path::PathBuf,
|
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;
|
pub struct Append;
|
||||||
|
|
||||||
impl Macro for Append {
|
impl Tool for Append {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "append",
|
identifier: "append",
|
||||||
description: "Append data to a file.",
|
description: "Append data to a file.",
|
||||||
group: "filesystem",
|
group: "filesystem",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::ListExact(vec![
|
||||||
|
ValueType::String,
|
||||||
|
ValueType::Any,
|
||||||
|
])],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,13 +36,16 @@ impl Macro for Append {
|
|||||||
|
|
||||||
pub struct CreateDir;
|
pub struct CreateDir;
|
||||||
|
|
||||||
impl Macro for CreateDir {
|
impl Tool for CreateDir {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "create_dir",
|
identifier: "create_dir",
|
||||||
description: "Create one or more directories.",
|
description: "Create one or more directories.",
|
||||||
group: "filesystem",
|
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;
|
pub struct FileMetadata;
|
||||||
|
|
||||||
impl Macro for FileMetadata {
|
impl Tool for FileMetadata {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "file_metadata",
|
identifier: "file_metadata",
|
||||||
description: "Get metadata for files.",
|
description: "Get metadata for files.",
|
||||||
group: "filesystem",
|
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;
|
pub struct ReadDir;
|
||||||
|
|
||||||
impl Macro for ReadDir {
|
impl Tool for ReadDir {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "read_dir",
|
identifier: "read_dir",
|
||||||
description: "Read the content of a directory.",
|
description: "Read the content of a directory.",
|
||||||
group: "filesystem",
|
group: "filesystem",
|
||||||
@ -168,9 +176,9 @@ impl Macro for ReadDir {
|
|||||||
|
|
||||||
pub struct ReadFile;
|
pub struct ReadFile;
|
||||||
|
|
||||||
impl Macro for ReadFile {
|
impl Tool for ReadFile {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "read_file",
|
identifier: "read_file",
|
||||||
description: "Read file contents.",
|
description: "Read file contents.",
|
||||||
group: "filesystem",
|
group: "filesystem",
|
||||||
@ -194,13 +202,16 @@ impl Macro for ReadFile {
|
|||||||
|
|
||||||
pub struct RemoveDir;
|
pub struct RemoveDir;
|
||||||
|
|
||||||
impl Macro for RemoveDir {
|
impl Tool for RemoveDir {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "remove_dir",
|
identifier: "remove_dir",
|
||||||
description: "Remove directories.",
|
description: "Remove directories.",
|
||||||
group: "filesystem",
|
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;
|
pub struct MoveDir;
|
||||||
|
|
||||||
impl Macro for MoveDir {
|
impl Tool for MoveDir {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "move_dir",
|
identifier: "move_dir",
|
||||||
description: "Move a directory to a new path.",
|
description: "Move a directory to a new path.",
|
||||||
group: "filesystem",
|
group: "filesystem",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::ListExact(vec![
|
||||||
|
ValueType::String,
|
||||||
|
ValueType::String,
|
||||||
|
])],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,13 +266,16 @@ impl Macro for MoveDir {
|
|||||||
|
|
||||||
pub struct Trash;
|
pub struct Trash;
|
||||||
|
|
||||||
impl Macro for Trash {
|
impl Tool for Trash {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "trash",
|
identifier: "trash",
|
||||||
description: "Move a file or directory to the trash.",
|
description: "Move a file or directory to the trash.",
|
||||||
group: "filesystem",
|
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;
|
pub struct Write;
|
||||||
|
|
||||||
impl Macro for Write {
|
impl Tool for Write {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "write",
|
identifier: "write",
|
||||||
description: "Write data to a file.",
|
description: "Write data to a file.",
|
||||||
group: "filesystem",
|
group: "filesystem",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::ListExact(vec![
|
||||||
|
ValueType::String,
|
||||||
|
ValueType::Any,
|
||||||
|
])],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,9 +327,9 @@ impl Macro for Write {
|
|||||||
|
|
||||||
pub struct RemoveFile;
|
pub struct RemoveFile;
|
||||||
|
|
||||||
impl Macro for RemoveFile {
|
impl Tool for RemoveFile {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "remove_file",
|
identifier: "remove_file",
|
||||||
description: "Permanently delete a file.",
|
description: "Permanently delete a file.",
|
||||||
group: "filesystem",
|
group: "filesystem",
|
||||||
@ -343,13 +363,13 @@ impl Macro for RemoveFile {
|
|||||||
|
|
||||||
pub struct Watch;
|
pub struct Watch;
|
||||||
|
|
||||||
impl Macro for Watch {
|
impl Tool for Watch {
|
||||||
fn info(&self) -> crate::MacroInfo<'static> {
|
fn info(&self) -> crate::ToolInfo<'static> {
|
||||||
crate::MacroInfo {
|
crate::ToolInfo {
|
||||||
identifier: "watch",
|
identifier: "watch",
|
||||||
description: "Wait until a file changes.",
|
description: "Wait until a file changes.",
|
||||||
group: "filesystem",
|
group: "filesystem",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::String],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,13 +2,13 @@ use std::{fs, thread::sleep, time::Duration};
|
|||||||
|
|
||||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||||
|
|
||||||
use crate::{Function, Macro, MacroInfo, Result, Value};
|
use crate::{Function, Result, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct Output;
|
pub struct Output;
|
||||||
|
|
||||||
impl Macro for Output {
|
impl Tool for Output {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "output",
|
identifier: "output",
|
||||||
description: "Print a value.",
|
description: "Print a value.",
|
||||||
group: "general",
|
group: "general",
|
||||||
@ -24,9 +24,9 @@ impl Macro for Output {
|
|||||||
}
|
}
|
||||||
pub struct Repeat;
|
pub struct Repeat;
|
||||||
|
|
||||||
impl Macro for Repeat {
|
impl Tool for Repeat {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "repeat",
|
identifier: "repeat",
|
||||||
description: "Run a function the given number of times.",
|
description: "Run a function the given number of times.",
|
||||||
group: "general",
|
group: "general",
|
||||||
@ -52,9 +52,9 @@ impl Macro for Repeat {
|
|||||||
|
|
||||||
pub struct Run;
|
pub struct Run;
|
||||||
|
|
||||||
impl Macro for Run {
|
impl Tool for Run {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "run",
|
identifier: "run",
|
||||||
description: "Run a whale file.",
|
description: "Run a whale file.",
|
||||||
group: "general",
|
group: "general",
|
||||||
@ -72,9 +72,9 @@ impl Macro for Run {
|
|||||||
|
|
||||||
pub struct Async;
|
pub struct Async;
|
||||||
|
|
||||||
impl Macro for Async {
|
impl Tool for Async {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "async",
|
identifier: "async",
|
||||||
description: "Run functions in parallel.",
|
description: "Run functions in parallel.",
|
||||||
group: "general",
|
group: "general",
|
||||||
@ -106,9 +106,9 @@ impl Macro for Async {
|
|||||||
|
|
||||||
pub struct Wait;
|
pub struct Wait;
|
||||||
|
|
||||||
impl Macro for Wait {
|
impl Tool for Wait {
|
||||||
fn info(&self) -> crate::MacroInfo<'static> {
|
fn info(&self) -> crate::ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "wait",
|
identifier: "wait",
|
||||||
description: "Wait for the given number of milliseconds.",
|
description: "Wait for the given number of milliseconds.",
|
||||||
group: "general",
|
group: "general",
|
@ -9,13 +9,13 @@ use eframe::{
|
|||||||
};
|
};
|
||||||
use egui_extras::{Column, StripBuilder, TableBuilder};
|
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;
|
pub struct CreateLine;
|
||||||
|
|
||||||
impl Macro for CreateLine {
|
impl Tool for CreateLine {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "create_line",
|
identifier: "create_line",
|
||||||
description: "Create a map value to be shown as a line in a plot.",
|
description: "Create a map value to be shown as a line in a plot.",
|
||||||
group: "gui",
|
group: "gui",
|
||||||
@ -40,9 +40,9 @@ impl Macro for CreateLine {
|
|||||||
|
|
||||||
pub struct BarGraph;
|
pub struct BarGraph;
|
||||||
|
|
||||||
impl Macro for BarGraph {
|
impl Tool for BarGraph {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "bar_graph",
|
identifier: "bar_graph",
|
||||||
description: "Render a list of values as a bar graph.",
|
description: "Render a list of values as a bar graph.",
|
||||||
group: "gui",
|
group: "gui",
|
||||||
@ -125,9 +125,9 @@ impl eframe::App for BarGraphGui {
|
|||||||
|
|
||||||
pub struct Plot;
|
pub struct Plot;
|
||||||
|
|
||||||
impl Macro for Plot {
|
impl Tool for Plot {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "plot",
|
identifier: "plot",
|
||||||
description: "Render a list of numbers as a scatter plot graph.",
|
description: "Render a list of numbers as a scatter plot graph.",
|
||||||
group: "gui",
|
group: "gui",
|
||||||
@ -193,9 +193,9 @@ impl eframe::App for PlotGui {
|
|||||||
|
|
||||||
pub struct Gui;
|
pub struct Gui;
|
||||||
|
|
||||||
impl Macro for Gui {
|
impl Tool for Gui {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "gui",
|
identifier: "gui",
|
||||||
description: "Display a value in a GUI window.",
|
description: "Display a value in a GUI window.",
|
||||||
group: "gui",
|
group: "gui",
|
@ -1,11 +1,11 @@
|
|||||||
use crate::{Error, Macro, MacroInfo, Result, Value, ValueType };
|
use crate::{Error, Tool, ToolInfo, Result, Value, ValueType };
|
||||||
|
|
||||||
|
|
||||||
pub struct Assert;
|
pub struct Assert;
|
||||||
|
|
||||||
impl Macro for Assert {
|
impl Tool for Assert {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "assert",
|
identifier: "assert",
|
||||||
description: "Panic if a boolean is false.",
|
description: "Panic if a boolean is false.",
|
||||||
group: "test",
|
group: "test",
|
||||||
@ -30,9 +30,9 @@ impl Macro for Assert {
|
|||||||
|
|
||||||
pub struct AssertEqual;
|
pub struct AssertEqual;
|
||||||
|
|
||||||
impl Macro for AssertEqual {
|
impl Tool for AssertEqual {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "assert_equal",
|
identifier: "assert_equal",
|
||||||
description: "Panic if two values do not match.",
|
description: "Panic if two values do not match.",
|
||||||
group: "test",
|
group: "test",
|
||||||
@ -54,9 +54,9 @@ impl Macro for AssertEqual {
|
|||||||
|
|
||||||
pub struct If;
|
pub struct If;
|
||||||
|
|
||||||
impl Macro for If {
|
impl Tool for If {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "if",
|
identifier: "if",
|
||||||
description: "Evaluates the first argument. If true, it does the second argument.",
|
description: "Evaluates the first argument. If true, it does the second argument.",
|
||||||
group: "logic",
|
group: "logic",
|
||||||
@ -92,9 +92,9 @@ impl Macro for If {
|
|||||||
|
|
||||||
pub struct IfElse;
|
pub struct IfElse;
|
||||||
|
|
||||||
impl Macro for IfElse {
|
impl Tool for IfElse {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "if_else",
|
identifier: "if_else",
|
||||||
description: "Evaluates the first argument. If true, it does the second argument. If false, it does the third argument",
|
description: "Evaluates the first argument. If true, it does the second argument. If false, it does the third argument",
|
||||||
group: "logic",
|
group: "logic",
|
||||||
@ -139,9 +139,9 @@ impl Macro for IfElse {
|
|||||||
|
|
||||||
pub struct Loop;
|
pub struct Loop;
|
||||||
|
|
||||||
impl Macro for Loop {
|
impl Tool for Loop {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "loop",
|
identifier: "loop",
|
||||||
description: "Repeats a function until the program ends.",
|
description: "Repeats a function until the program ends.",
|
||||||
group: "general",
|
group: "general",
|
@ -2,17 +2,27 @@
|
|||||||
//!
|
//!
|
||||||
//! ## Writing macros
|
//! ## Writing macros
|
||||||
//!
|
//!
|
||||||
//! - snake case identifier, this is enforced by a test
|
//! - Snake case identifier, this is enforced by a test
|
||||||
//! - the description should be brief, it will display in the shell
|
//! - 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
|
//! ## 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]);
|
//! # use dust_lib::{tools::collections::Count, Tool, Value};
|
||||||
//! let count = Count.run(value).as_string().unwrap();
|
//! 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);
|
//! 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
|
/// This list is used to match identifiers with macros and to provide info to
|
||||||
/// the shell.
|
/// the shell.
|
||||||
pub const MACRO_LIST: [&'static dyn Macro; 57] = [
|
pub const TOOL_LIST: [&'static dyn Tool; 57] = [
|
||||||
&collections::Count,
|
&collections::Count,
|
||||||
&collections::CreateTable,
|
&collections::CreateTable,
|
||||||
&collections::Get,
|
&collections::Get,
|
||||||
@ -98,14 +108,14 @@ pub const MACRO_LIST: [&'static dyn Macro; 57] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
/// A whale macro function.
|
/// A whale macro function.
|
||||||
pub trait Macro: Sync + Send {
|
pub trait Tool: Sync + Send {
|
||||||
fn info(&self) -> MacroInfo<'static>;
|
fn info(&self) -> ToolInfo<'static>;
|
||||||
fn run(&self, argument: &Value) -> Result<Value>;
|
fn run(&self, argument: &Value) -> Result<Value>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information needed for each macro.
|
/// Information needed for each macro.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct MacroInfo<'a> {
|
pub struct ToolInfo<'a> {
|
||||||
/// Text pattern that triggers this macro.
|
/// Text pattern that triggers this macro.
|
||||||
pub identifier: &'a str,
|
pub identifier: &'a str,
|
||||||
|
|
||||||
@ -350,7 +360,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn macro_formatting() {
|
fn macro_formatting() {
|
||||||
for function in MACRO_LIST {
|
for function in TOOL_LIST {
|
||||||
let identifier = function.info().identifier;
|
let identifier = function.info().identifier;
|
||||||
|
|
||||||
assert_eq!(identifier.to_lowercase(), identifier);
|
assert_eq!(identifier.to_lowercase(), identifier);
|
@ -1,12 +1,12 @@
|
|||||||
//! Macros for network access.
|
//! Macros for network access.
|
||||||
|
|
||||||
use crate::{Macro, MacroInfo, Result, Value};
|
use crate::{Result, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct Download;
|
pub struct Download;
|
||||||
|
|
||||||
impl Macro for Download {
|
impl Tool for Download {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "download",
|
identifier: "download",
|
||||||
description: "Fetch a network resource.",
|
description: "Fetch a network resource.",
|
||||||
group: "network",
|
group: "network",
|
@ -1,12 +1,12 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::{Error, Macro, MacroInfo, Result, Value};
|
use crate::{Error, Result, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct CoprRepositories;
|
pub struct CoprRepositories;
|
||||||
|
|
||||||
impl Macro for CoprRepositories {
|
impl Tool for CoprRepositories {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "enable_copr_repository",
|
identifier: "enable_copr_repository",
|
||||||
description: "Enable one or more COPR repositories.",
|
description: "Enable one or more COPR repositories.",
|
||||||
group: "package management",
|
group: "package management",
|
||||||
@ -37,9 +37,9 @@ impl Macro for CoprRepositories {
|
|||||||
|
|
||||||
pub struct InstallPackage;
|
pub struct InstallPackage;
|
||||||
|
|
||||||
impl Macro for InstallPackage {
|
impl Tool for InstallPackage {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "install_package",
|
identifier: "install_package",
|
||||||
description: "Install one or more packages.",
|
description: "Install one or more packages.",
|
||||||
group: "package management",
|
group: "package management",
|
||||||
@ -73,9 +73,9 @@ impl Macro for InstallPackage {
|
|||||||
|
|
||||||
pub struct EnableRpmRepositories;
|
pub struct EnableRpmRepositories;
|
||||||
|
|
||||||
impl Macro for EnableRpmRepositories {
|
impl Tool for EnableRpmRepositories {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "enable_rpm_repositories",
|
identifier: "enable_rpm_repositories",
|
||||||
description: "Enable one or more RPM repositories.",
|
description: "Enable one or more RPM repositories.",
|
||||||
group: "package management",
|
group: "package management",
|
||||||
@ -110,9 +110,9 @@ impl Macro for EnableRpmRepositories {
|
|||||||
|
|
||||||
pub struct UninstallPackage;
|
pub struct UninstallPackage;
|
||||||
|
|
||||||
impl Macro for UninstallPackage {
|
impl Tool for UninstallPackage {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "uninstall_package",
|
identifier: "uninstall_package",
|
||||||
description: "Uninstall one or more packages.",
|
description: "Uninstall one or more packages.",
|
||||||
group: "package management",
|
group: "package management",
|
||||||
@ -146,9 +146,9 @@ impl Macro for UninstallPackage {
|
|||||||
|
|
||||||
pub struct UpgradePackages;
|
pub struct UpgradePackages;
|
||||||
|
|
||||||
impl Macro for UpgradePackages {
|
impl Tool for UpgradePackages {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "upgrade_packages",
|
identifier: "upgrade_packages",
|
||||||
description: "Upgrade all installed packages.",
|
description: "Upgrade all installed packages.",
|
||||||
group: "package management",
|
group: "package management",
|
@ -2,13 +2,13 @@ use std::convert::TryInto;
|
|||||||
|
|
||||||
use rand::{random, thread_rng, Rng};
|
use rand::{random, thread_rng, Rng};
|
||||||
|
|
||||||
use crate::{Error, Macro, MacroInfo, Result, Value};
|
use crate::{Error, Result, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct RandomBoolean;
|
pub struct RandomBoolean;
|
||||||
|
|
||||||
impl Macro for RandomBoolean {
|
impl Tool for RandomBoolean {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "random_boolean",
|
identifier: "random_boolean",
|
||||||
description: "Create a random boolean.",
|
description: "Create a random boolean.",
|
||||||
group: "random",
|
group: "random",
|
||||||
@ -27,9 +27,9 @@ impl Macro for RandomBoolean {
|
|||||||
|
|
||||||
pub struct RandomInteger;
|
pub struct RandomInteger;
|
||||||
|
|
||||||
impl Macro for RandomInteger {
|
impl Tool for RandomInteger {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "random_integer",
|
identifier: "random_integer",
|
||||||
description: "Create a random integer.",
|
description: "Create a random integer.",
|
||||||
group: "random",
|
group: "random",
|
||||||
@ -61,9 +61,9 @@ impl Macro for RandomInteger {
|
|||||||
|
|
||||||
pub struct RandomString;
|
pub struct RandomString;
|
||||||
|
|
||||||
impl Macro for RandomString {
|
impl Tool for RandomString {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "random_string",
|
identifier: "random_string",
|
||||||
description: "Generate a random string.",
|
description: "Generate a random string.",
|
||||||
group: "random",
|
group: "random",
|
||||||
@ -105,9 +105,9 @@ impl Macro for RandomString {
|
|||||||
|
|
||||||
pub struct RandomFloat;
|
pub struct RandomFloat;
|
||||||
|
|
||||||
impl Macro for RandomFloat {
|
impl Tool for RandomFloat {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "random_float",
|
identifier: "random_float",
|
||||||
description: "Generate a random floating point value between 0 and 1.",
|
description: "Generate a random floating point value between 0 and 1.",
|
||||||
group: "random",
|
group: "random",
|
||||||
@ -124,9 +124,9 @@ impl Macro for RandomFloat {
|
|||||||
|
|
||||||
pub struct Random;
|
pub struct Random;
|
||||||
|
|
||||||
impl Macro for Random {
|
impl Tool for Random {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "random",
|
identifier: "random",
|
||||||
description: "Select a random item from a collection.",
|
description: "Select a random item from a collection.",
|
||||||
group: "random",
|
group: "random",
|
@ -1,12 +1,12 @@
|
|||||||
use sys_info::cpu_speed;
|
use sys_info::cpu_speed;
|
||||||
|
|
||||||
use crate::{Macro, MacroInfo, Result, Value};
|
use crate::{Result, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct CpuSpeed;
|
pub struct CpuSpeed;
|
||||||
|
|
||||||
impl Macro for CpuSpeed {
|
impl Tool for CpuSpeed {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "cpu_speed",
|
identifier: "cpu_speed",
|
||||||
description: "Return the current processor speed in megahertz.",
|
description: "Return the current processor speed in megahertz.",
|
||||||
group: "system",
|
group: "system",
|
@ -1,12 +1,12 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use crate::{Macro, MacroInfo, Result, Time, Value};
|
use crate::{Result, Time, Tool, ToolInfo, Value};
|
||||||
|
|
||||||
pub struct Now;
|
pub struct Now;
|
||||||
|
|
||||||
impl Macro for Now {
|
impl Tool for Now {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "now",
|
identifier: "now",
|
||||||
description: "Return the current time.",
|
description: "Return the current time.",
|
||||||
group: "time",
|
group: "time",
|
||||||
@ -25,9 +25,9 @@ impl Macro for Now {
|
|||||||
|
|
||||||
pub struct Local;
|
pub struct Local;
|
||||||
|
|
||||||
impl Macro for Local {
|
impl Tool for Local {
|
||||||
fn info(&self) -> MacroInfo<'static> {
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
MacroInfo {
|
ToolInfo {
|
||||||
identifier: "local",
|
identifier: "local",
|
||||||
description: "Show a time value adjusted for the current time zone.",
|
description: "Show a time value adjusted for the current time zone.",
|
||||||
group: "time",
|
group: "time",
|
@ -4,7 +4,7 @@ use std::{
|
|||||||
fmt::{self, Display, Formatter},
|
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.
|
/// A context that stores its mappings in hash maps.
|
||||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
|
#[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> {
|
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;
|
let valid_input_types = macro_item.info().inputs;
|
||||||
|
|
||||||
if identifier == macro_item.info().identifier {
|
if identifier == macro_item.info().identifier {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
use whale_lib::*;
|
use dust_lib::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn collections() {
|
fn collections() {
|
||||||
|
Loading…
Reference in New Issue
Block a user