From f35ba583818d0604b722eb698a19d115265b5698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:53:15 +0800 Subject: [PATCH] refactor(main): improve structure --- src/commands/mod.rs | 3 +++ src/{ => commands}/run.rs | 0 src/main.rs | 47 +++++---------------------------------- src/utils/mod.rs | 3 +++ src/utils/styles.rs | 37 ++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 src/commands/mod.rs rename src/{ => commands}/run.rs (100%) create mode 100644 src/utils/mod.rs create mode 100644 src/utils/styles.rs diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000..caa8049 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,3 @@ +mod run; + +pub use run::run; diff --git a/src/run.rs b/src/commands/run.rs similarity index 100% rename from src/run.rs rename to src/commands/run.rs diff --git a/src/main.rs b/src/main.rs index 20e148b..886fc07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,49 +6,12 @@ use clap::{Parser, Subcommand}; use hatsu_utils::AppError; use human_panic::{metadata, setup_panic}; -mod run; - -pub const fn get_styles() -> clap::builder::Styles { - clap::builder::Styles::styled() - .usage( - anstyle::Style::new() - .bold() - .underline() - .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::BrightCyan))), - ) - .header( - anstyle::Style::new() - .bold() - .underline() - .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::BrightCyan))), - ) - .literal( - anstyle::Style::new().fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Magenta))), - ) - .invalid( - anstyle::Style::new() - .bold() - .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))), - ) - .error( - anstyle::Style::new() - .bold() - .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))), - ) - .valid( - anstyle::Style::new() - .bold() - .underline() - .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Magenta))), - ) - .placeholder( - anstyle::Style::new().fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::White))), - ) -} +mod commands; +mod utils; #[derive(Debug, Parser)] #[command( - styles = get_styles(), + styles = utils::styles(), name = "hatsu", version = hatsu_utils::VERSION, about, @@ -71,9 +34,9 @@ async fn main() -> Result<(), AppError> { if let Some(command) = args.command { match command { - Commands::Run => run::run().await, + Commands::Run => commands::run().await, } } else { - run::run().await + commands::run().await } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..8205a4b --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1,3 @@ +mod styles; + +pub use styles::styles; diff --git a/src/utils/styles.rs b/src/utils/styles.rs new file mode 100644 index 0000000..59056c4 --- /dev/null +++ b/src/utils/styles.rs @@ -0,0 +1,37 @@ +use anstyle::{AnsiColor, Color, Style}; +use clap::builder::Styles; + +#[must_use] +pub const fn styles() -> Styles { + Styles::styled() + .usage( + Style::new() + .bold() + .underline() + .fg_color(Some(Color::Ansi(AnsiColor::BrightCyan))), + ) + .header( + Style::new() + .bold() + .underline() + .fg_color(Some(Color::Ansi(AnsiColor::BrightCyan))), + ) + .literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Magenta)))) + .invalid( + Style::new() + .bold() + .fg_color(Some(Color::Ansi(AnsiColor::Red))), + ) + .error( + Style::new() + .bold() + .fg_color(Some(Color::Ansi(AnsiColor::Red))), + ) + .valid( + Style::new() + .bold() + .underline() + .fg_color(Some(Color::Ansi(AnsiColor::Magenta))), + ) + .placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::White)))) +}