From db9228dec49b740fb2b353304c8a65e9ac0843ab Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Mon, 19 Feb 2024 18:07:09 +0100 Subject: [PATCH] cli: add dev command for enums experiment --- Cargo.lock | 1 + crates/app/Cargo.toml | 1 + crates/app/src/main.rs | 36 +++++++++++++++++++++++++++++++--- crates/prowocessing/src/lib.rs | 9 ++++++++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e97cb16..123e4ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,7 @@ dependencies = [ "eval", "ir", "owo-colors", + "prowocessing", "ron", "serde", "serde_json", diff --git a/crates/app/Cargo.toml b/crates/app/Cargo.toml index 10182c2..d316efc 100644 --- a/crates/app/Cargo.toml +++ b/crates/app/Cargo.toml @@ -12,6 +12,7 @@ clap = { workspace = true, features = [ "derive", "env" ] } dirs = "5" eval = { path = "../eval" } ir = { path = "../ir" } +prowocessing = { path = "../prowocessing"} owo-colors = "4" ron = "0.8" serde = { workspace = true, features = [ "derive" ] } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 7d7eff2..2caaa2f 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -2,6 +2,7 @@ use std::{fs, path::PathBuf}; use clap::{Parser, Subcommand}; use config::{CliConfigs, Config}; +use dev::DevCommands; use welcome_msg::print_startup_msg; mod config; @@ -24,7 +25,10 @@ enum Commands { /// What file contains the pipeline to evaluate. source: PathBuf, }, - Dev, + Dev { + #[command(subcommand)] + dev_command: DevCommands, + }, } fn main() { @@ -46,8 +50,34 @@ fn main() { machine.feed(ir); machine.eval_full(); } - Commands::Dev => { - println!("Hello world!"); + Commands::Dev { dev_command } => dev_command.run(), + } +} + +mod dev { + use clap::Subcommand; + use prowocessing::experimental::enum_based::{Pipeline, PipelineBuilder}; + + #[derive(Subcommand)] + pub(crate) enum DevCommands { + Enums { test_str: String }, + } + + impl DevCommands { + pub fn run(self) { + match self { + DevCommands::Enums { test_str } => { + let upr = PipelineBuilder::new() + .insert(prowocessing::experimental::enum_based::Instruction::Uppercase) + .build(); + let lwr = PipelineBuilder::new() + .insert(prowocessing::experimental::enum_based::Instruction::Lowercase) + .build(); + + println!("Upr: {}", upr.run(test_str.clone())); + println!("Lwr: {}", lwr.run(test_str.clone())); + } + } } } } diff --git a/crates/prowocessing/src/lib.rs b/crates/prowocessing/src/lib.rs index 8affe30..778d544 100644 --- a/crates/prowocessing/src/lib.rs +++ b/crates/prowocessing/src/lib.rs @@ -7,7 +7,7 @@ use experimental::enum_based::{Instruction, PipelineBuilder}; /// just some experiments, to test whether the architecture i want is even possible (or how to do it). probably temporary. /// Gonna first try string processing... -mod experimental { +pub mod experimental { pub mod enum_based { pub enum Instruction { Uppercase, @@ -41,6 +41,7 @@ mod experimental { } } + #[must_use] pub fn insert(mut self, instr: Instruction) -> Self { self.pipeline.push(instr); self @@ -66,6 +67,12 @@ mod experimental { Pipeline { pipeline: res } } } + + impl Default for PipelineBuilder { + fn default() -> Self { + Self::new() + } + } } }