Skip to content

Commit

Permalink
refactor(main): improve structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Oct 28, 2024
1 parent f7a9afa commit f35ba58
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 42 deletions.
3 changes: 3 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod run;

pub use run::run;
File renamed without changes.
47 changes: 5 additions & 42 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
}
3 changes: 3 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod styles;

pub use styles::styles;
37 changes: 37 additions & 0 deletions src/utils/styles.rs
Original file line number Diff line number Diff line change
@@ -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))))
}

0 comments on commit f35ba58

Please sign in to comment.