Skip to content

Commit

Permalink
fix: command help info.
Browse files Browse the repository at this point in the history
  • Loading branch information
auula committed Jul 1, 2024
1 parent ecf238f commit b1cc04d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ const INIT_HELP_TEXT: &str = r"
";

static HELPS: Lazy<Mutex<HashMap<Command, colored::ColoredString>>> = Lazy::new(|| {
let mut helps: HashMap<Command, colored::ColoredString> = HashMap::new();
static HELP_INFO: Lazy<Mutex<HashMap<Command, colored::ColoredString>>> = Lazy::new(|| {
let mut help_info: HashMap<Command, colored::ColoredString> = HashMap::new();

helps.insert(Command::Theme, THEME_HELP_TEXT.green());
helps.insert(Command::Build, BUILD_HELP_TEXT.green());
helps.insert(Command::Init, INIT_HELP_TEXT.green());
help_info.insert(Command::Theme, THEME_HELP_TEXT.green());
help_info.insert(Command::Build, BUILD_HELP_TEXT.green());
help_info.insert(Command::Init, INIT_HELP_TEXT.green());

Mutex::new(helps)
Mutex::new(help_info)
});

pub fn handle_theme_command(args: &[String], _log: &mut Logger) {
Expand All @@ -98,10 +98,10 @@ pub fn handle_theme_command(args: &[String], _log: &mut Logger) {
// 通过命令行传入的 args 参数打印 help 信息
pub fn handle_help_command(args: &[String], _log: &mut Logger) {
if let Some(option) = args.get(0) {
let helps = HELPS.lock().unwrap();
let help = HELP_INFO.lock().unwrap();
match Command::from_str(option) {
Command::Build | Command::Theme | Command::Init | Command::Help => {
if let Some(help_text) = helps.get(&Command::from_str(option)) {
if let Some(help_text) = help.get(&Command::from_str(option)) {
println!("{}", help_text);
} else {
eprintln!("No help available for command: {}", option);
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use typikon::{cli::Command, utils::Logger};

fn main() {

let mut log = Logger::console_log();
let (command, args) = typikon::cli::parse_args();

Expand All @@ -11,4 +12,5 @@ fn main() {
Command::Theme => typikon::cli::handle_theme_command(&args, &mut log),
Command::Unknown(_) => typikon::cli::out_banner_string(),
}

}

0 comments on commit b1cc04d

Please sign in to comment.