1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

version and help

This commit is contained in:
Robin Appelman 2025-09-01 16:55:58 +02:00
commit e189b2e4f2
5 changed files with 188 additions and 86 deletions

44
src/help.rs Normal file
View file

@ -0,0 +1,44 @@
use crate::args::HazeCommand;
use owo_colors::colors::xterm::Gray;
use owo_colors::OwoColorize;
use strum::{EnumMessage, IntoEnumIterator};
pub fn help() {
println!(
"{} {} {}",
"Usage:".bright_yellow().bold(),
"haze".blue(),
"[filter] <COMMAND> [arguments]".green()
);
println!();
println!("{}", "Commands:".yellow().bold());
let max_command_len = HazeCommand::iter()
.map(|command| <&'static str>::from(command).len())
.max()
.unwrap();
let max_doc_len = HazeCommand::iter()
.map(|command| command.get_documentation().unwrap_or_default().len())
.max()
.unwrap();
for command in HazeCommand::iter() {
let command: HazeCommand = command;
let command_str = <&'static str>::from(command);
let mut len = command_str.len();
if command_str.starts_with("--") {
len -= 2;
}
println!(
" {}{} {}{} {}",
command.blue(),
" ".repeat(max_command_len - len),
command.get_documentation().unwrap_or_default(),
" ".repeat(max_doc_len - command.get_documentation().unwrap_or_default().len()),
if command.allows_filter() {
"- supports filter".fg::<Gray>()
} else {
"".fg::<Gray>()
},
);
}
}