From c04a17fe47eb091c4c533cc816b7806fcdacf975 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 19 Nov 2024 18:53:40 -0800 Subject: [PATCH] start impl for new command system maid -h maid --health maid -l maid --list maid -C maid --clean-cache maid -i maid --init maid -p maid --project maid -e maid --env maid -s health maid --server health maid -r maid --remote maid -g maid --system --- Cargo.toml | 2 +- Maidfile.toml | 16 ++++------------ maid/client/cli/butler.rs | 14 +++++++------- maid/client/main.rs | 30 ++++++++++++++++++++++++------ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2673521..0c4f818 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "BSL-1.1" build = "build/attribute.rs" repository = "https://github.com/exact-rs/maid" -description = "🔨 An easy to use make alternative." +description = "🔨 A comprehensive build tool for all your needs." [[bin]] name = "maid" diff --git a/Maidfile.toml b/Maidfile.toml index d0a1f15..17d1a7d 100644 --- a/Maidfile.toml +++ b/Maidfile.toml @@ -12,11 +12,7 @@ version = "2.0.0" # Build on a remote server [project.server] token = "test_token1" -address = { - host = "localhost", - port = 3500, - ssl = false -} +address = { host = "localhost", port = 3500, ssl = false } # Global environment (applied to shell) [env] @@ -31,7 +27,8 @@ VERSION='2.0.0' info = "Build binaries" depends = ["clean"] script = [ - "cargo zigbuild --release --all-features --color always", + "cargo zigbuild --release --no-default-features --features client --color always", + # "cargo zigbuild --release --all-features --color always", "mv target/release/maid bin/maid", "mv target/release/maid-server bin/maid-server", ] @@ -54,9 +51,4 @@ pull = "bin" [tasks] clean.script = ["rm -rf bin", "mkdir bin"] install.script =["maid build -q","sudo cp bin/maid /usr/local/bin", "maid -V"] - -api_server = { - path = "bin", - depends = ["build"], - script = "./maid_server" -} \ No newline at end of file +api_server = { path = "bin", depends = ["build"], script = "./maid_server" } \ No newline at end of file diff --git a/maid/client/cli/butler.rs b/maid/client/cli/butler.rs index 71b3b44..484553b 100644 --- a/maid/client/cli/butler.rs +++ b/maid/client/cli/butler.rs @@ -7,9 +7,9 @@ use notify::RecursiveMode; use notify_debouncer_mini::new_debouncer; use std::{fs::File, io::Write, path::Path, time::Duration}; -fn create_error(name: &str) { +fn create_error(name: &str, path: &str) { println!("An error happened when asking for {name}, try again later."); - std::fs::remove_file("maidfile").unwrap(); + std::fs::remove_file(path).unwrap(); std::process::exit(1); } @@ -27,13 +27,13 @@ pub fn watch(path: &Path) { pub fn update() { println!("check and retrive updates") } -pub fn init() { +pub fn init(path: String) { let example_maidfile = "[tasks.example]\ninfo = \"this is a comment\"\nscript = \"echo 'hello world'\""; - if !helpers::Exists::file(string!("maidfile")).unwrap() { + if !helpers::Exists::file(path.to_owned()).unwrap() { println!("This utility will walk you through creating a maidfile.\n"); - let mut file = File::create("maidfile").unwrap(); + let mut file = File::create(&path).unwrap(); let current_dir = std::env::current_dir().unwrap(); writeln!(&mut file, "[project]").unwrap(); @@ -42,11 +42,11 @@ pub fn init() { match name { Ok(name) => writeln!(&mut file, "name = \"{name}\"").unwrap(), - Err(_) => create_error("project name"), + Err(_) => create_error("project name", &path), } match version { Ok(version) => writeln!(&mut file, "version = \"{version}\"").unwrap(), - Err(_) => create_error("version"), + Err(_) => create_error("version", &path), } writeln!(&mut file, "\n{example_maidfile}").unwrap(); diff --git a/maid/client/main.rs b/maid/client/main.rs index 38cc5f3..8316a7a 100644 --- a/maid/client/main.rs +++ b/maid/client/main.rs @@ -11,7 +11,18 @@ mod task; use clap::{Parser, Subcommand}; use clap_verbosity_flag::Verbosity; use macros_rs::str; -use std::path::Path; +use std::{io::Result, path::Path}; + +type File = Option; + +fn parse_init(arg: &str) -> Result { + let s = arg.to_string(); + let path = match s.starts_with('-') { + true => Some("maidfile".into()), + false => Some(s), + }; + Ok(path) +} #[derive(Parser)] #[command(version = str!(cli::get_version(false)))] @@ -19,10 +30,15 @@ struct Cli { /// Run a task defined in maidfile #[arg(default_value = "", hide_default_value = true)] task: Vec, - #[arg(global = true, short, long, default_value_t = String::from("maidfile"), help = "maidfile path")] + /// Base path for Maidfile + #[arg(global = true, short, long, default_value = "maidfile")] path: String, - #[arg(short, long, help = "force rebuild")] + /// Ignore cache on build + #[arg(short, long)] force: bool, + /// Create new Maid project + #[arg(short, long, value_parser = parse_init)] + init: Option, #[command(subcommand)] command: Option, #[clap(flatten)] @@ -48,11 +64,10 @@ enum Commands { #[derive(Subcommand)] enum Butler { /// List all maidfile tasks + #[command(visible_alias = "ls", visible_alias = "list")] Tasks, /// Get Project Info Info, - /// Create new maidfile - Init, /// Clear maid cache Clean, /// Watch maidfile task @@ -82,12 +97,15 @@ fn main() { globals::init(); env_logger::Builder::new().filter_level(cli.verbose.log_level_filter()).init(); + if let Some(path) = cli.init { + return cli::butler::init(path.expect("Expected valid path")); + } + match &cli.command { Some(Commands::Butler { internal }) => match internal { Butler::Json { hydrate } => cli::tasks::json(&cli.path, &cli.task, hydrate), Butler::Info => cli::info(&cli.path), Butler::Clean => cli::butler::clean(), - Butler::Init => cli::butler::init(), Butler::Watch => cli::butler::watch(Path::new("src")), Butler::Update => cli::butler::update(), Butler::Tasks => cli::tasks::List::all(&cli.path, cli.verbose.is_silent(), cli.verbose.log_level(), cli.force), -- GitLab