Add type checks
This commit is contained in:
parent
8721ad41b1
commit
eb953b0231
@ -53,9 +53,9 @@ impl Tool for Repeat {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Async;
|
||||
pub struct Run;
|
||||
|
||||
impl Tool for Async {
|
||||
impl Tool for Run {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "run",
|
||||
|
@ -9,34 +9,9 @@ use eframe::{
|
||||
};
|
||||
use egui_extras::{Column, StripBuilder, TableBuilder};
|
||||
|
||||
use crate::{eval_with_context, Error, Result, Table, Tool, ToolInfo, Value, VariableMap};
|
||||
|
||||
pub struct CreateLine;
|
||||
|
||||
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",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
let argument = argument.as_list()?;
|
||||
let index = argument[0].as_int()?.clone();
|
||||
let height = argument[1].as_float()?.clone();
|
||||
let name = argument[2].clone();
|
||||
let mut line = VariableMap::new();
|
||||
|
||||
line.set_value("index", Value::Float(index as f64))?;
|
||||
line.set_value("height", Value::Float(height))?;
|
||||
line.set_value("name", name)?;
|
||||
|
||||
Ok(Value::Map(line))
|
||||
}
|
||||
}
|
||||
use crate::{
|
||||
eval_with_context, Error, Result, Table, Tool, ToolInfo, Value, ValueType, VariableMap,
|
||||
};
|
||||
|
||||
pub struct BarGraph;
|
||||
|
||||
@ -46,7 +21,7 @@ impl Tool for BarGraph {
|
||||
identifier: "bar_graph",
|
||||
description: "Render a list of values as a bar graph.",
|
||||
group: "gui",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::ListOf(Box::new(ValueType::List))],
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +106,7 @@ impl Tool for Plot {
|
||||
identifier: "plot",
|
||||
description: "Render a list of numbers as a scatter plot graph.",
|
||||
group: "gui",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::ListOf(Box::new(ValueType::Integer))],
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,32 +166,6 @@ impl eframe::App for PlotGui {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Gui;
|
||||
|
||||
impl Tool for Gui {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "gui",
|
||||
description: "Display a value in a GUI window.",
|
||||
group: "gui",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
let argument = argument.clone();
|
||||
|
||||
run_native(
|
||||
&argument.value_type().to_string(),
|
||||
NativeOptions::default(),
|
||||
Box::new(|_cc| Box::new(GuiApp::new(Ok(argument)))),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Ok(Value::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GuiApp {
|
||||
text_edit_buffer: String,
|
||||
whale_context: VariableMap,
|
||||
|
@ -145,7 +145,7 @@ impl Tool for Loop {
|
||||
identifier: "loop",
|
||||
description: "Repeats a function until the program ends.",
|
||||
group: "general",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Function],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ pub mod general;
|
||||
pub mod gui;
|
||||
pub mod logic;
|
||||
pub mod network;
|
||||
pub mod package_management;
|
||||
pub mod random;
|
||||
pub mod system;
|
||||
pub mod time;
|
||||
@ -51,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; 55] = [
|
||||
pub const TOOL_LIST: [&'static dyn Tool; 49] = [
|
||||
&collections::Count,
|
||||
&collections::CreateTable,
|
||||
&collections::Insert,
|
||||
@ -81,22 +80,16 @@ pub const TOOL_LIST: [&'static dyn Tool; 55] = [
|
||||
&filesystem::Trash,
|
||||
&filesystem::Watch,
|
||||
&filesystem::Write,
|
||||
&general::Async,
|
||||
&general::Run,
|
||||
&general::Output,
|
||||
&general::Repeat,
|
||||
&general::Wait,
|
||||
&gui::BarGraph,
|
||||
&gui::Plot,
|
||||
&gui::Gui,
|
||||
&logic::If,
|
||||
&logic::IfElse,
|
||||
&logic::Loop,
|
||||
&network::Download,
|
||||
&package_management::CoprRepositories,
|
||||
&package_management::EnableRpmRepositories,
|
||||
&package_management::InstallPackage,
|
||||
&package_management::UninstallPackage,
|
||||
&package_management::UpgradePackages,
|
||||
&random::Random,
|
||||
&random::RandomBoolean,
|
||||
&random::RandomFloat,
|
||||
|
@ -1,170 +0,0 @@
|
||||
use std::process::Command;
|
||||
|
||||
use crate::{Error, Result, Tool, ToolInfo, Value};
|
||||
|
||||
pub struct CoprRepositories;
|
||||
|
||||
impl Tool for CoprRepositories {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "enable_copr_repository",
|
||||
description: "Enable one or more COPR repositories.",
|
||||
group: "package management",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
let repo_list_string = if let Ok(repo) = argument.as_string().cloned() {
|
||||
repo
|
||||
} else if let Ok(repos) = argument.as_list() {
|
||||
repos.iter().map(|value| value.to_string() + " ").collect()
|
||||
} else {
|
||||
return Err(crate::Error::ExpectedString {
|
||||
actual: argument.clone(),
|
||||
});
|
||||
};
|
||||
|
||||
Command::new("fish")
|
||||
.arg("-c")
|
||||
.arg(format!("sudo dnf -y copr enable {repo_list_string}"))
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
|
||||
Ok(Value::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InstallPackage;
|
||||
|
||||
impl Tool for InstallPackage {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "install_package",
|
||||
description: "Install one or more packages.",
|
||||
group: "package management",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
let package_list_string = if let Ok(package) = argument.as_string().cloned() {
|
||||
package
|
||||
} else if let Ok(packages) = argument.as_list() {
|
||||
packages
|
||||
.iter()
|
||||
.map(|value| value.to_string() + " ")
|
||||
.collect()
|
||||
} else {
|
||||
return Err(Error::ExpectedString {
|
||||
actual: argument.clone(),
|
||||
});
|
||||
};
|
||||
|
||||
Command::new("fish")
|
||||
.arg("-c")
|
||||
.arg(format!("sudo dnf -y install {package_list_string}"))
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
|
||||
Ok(Value::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnableRpmRepositories;
|
||||
|
||||
impl Tool for EnableRpmRepositories {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "enable_rpm_repositories",
|
||||
description: "Enable one or more RPM repositories.",
|
||||
group: "package management",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
if let Ok(repo) = argument.as_string() {
|
||||
Command::new("fish")
|
||||
.arg("-c")
|
||||
.arg(format!("sudo dnf -y config-manager --add-repo {repo}"))
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
} else if let Ok(repos) = argument.as_list() {
|
||||
for repo in repos {
|
||||
Command::new("fish")
|
||||
.arg("-c")
|
||||
.arg(format!("sudo dnf -y config-manager --add-repo {repo}"))
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
}
|
||||
} else {
|
||||
return Err(crate::Error::ExpectedString {
|
||||
actual: argument.clone(),
|
||||
});
|
||||
};
|
||||
|
||||
Ok(Value::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UninstallPackage;
|
||||
|
||||
impl Tool for UninstallPackage {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "uninstall_package",
|
||||
description: "Uninstall one or more packages.",
|
||||
group: "package management",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
let package_list_string = if let Ok(package) = argument.as_string().cloned() {
|
||||
package
|
||||
} else if let Ok(packages) = argument.as_list() {
|
||||
packages
|
||||
.iter()
|
||||
.map(|value| value.to_string() + " ")
|
||||
.collect()
|
||||
} else {
|
||||
return Err(Error::ExpectedString {
|
||||
actual: argument.clone(),
|
||||
});
|
||||
};
|
||||
|
||||
Command::new("fish")
|
||||
.arg("-c")
|
||||
.arg(format!("sudo dnf -y remove {package_list_string}"))
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
|
||||
Ok(Value::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UpgradePackages;
|
||||
|
||||
impl Tool for UpgradePackages {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "upgrade_packages",
|
||||
description: "Upgrade all installed packages.",
|
||||
group: "package management",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
argument.as_empty()?;
|
||||
|
||||
Command::new("fish")
|
||||
.arg("-c")
|
||||
.arg("sudo dnf -y upgrade")
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
|
||||
Ok(Value::Empty)
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use sys_info::cpu_speed;
|
||||
|
||||
use crate::{Result, Tool, ToolInfo, Value};
|
||||
use crate::{Result, Tool, ToolInfo, Value, ValueType};
|
||||
|
||||
pub struct CpuSpeed;
|
||||
|
||||
@ -10,7 +10,7 @@ impl Tool for CpuSpeed {
|
||||
identifier: "cpu_speed",
|
||||
description: "Return the current processor speed in megahertz.",
|
||||
group: "system",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Empty],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::{Result, Time, Tool, ToolInfo, Value};
|
||||
use crate::{Result, Time, Tool, ToolInfo, Value, ValueType};
|
||||
|
||||
pub struct Now;
|
||||
|
||||
@ -10,7 +10,7 @@ impl Tool for Now {
|
||||
identifier: "now",
|
||||
description: "Return the current time.",
|
||||
group: "time",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Empty],
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ impl Tool for Local {
|
||||
identifier: "local",
|
||||
description: "Show a time value adjusted for the current time zone.",
|
||||
group: "time",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Time],
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user