feat: colour the help, and check the command definition

This commit is contained in:
2026-09-08 09:58:02 +00:00
parent 4b1e9d68b0
commit 061b77f619

View File

@@ -1,10 +1,12 @@
use super::{Django, Link, Postgres}; use super::{Django, Link, Postgres};
use clap::builder::styling::{AnsiColor, Effects, Styles};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use clap_complete::Shell; use clap_complete::Shell;
/// A program for interacting with various dockerized applications /// A program for interacting with various dockerized applications
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about=None)] #[command(version, about, long_about = None)]
#[command(styles = help_styles())]
pub struct Ahab { pub struct Ahab {
#[command(subcommand)] #[command(subcommand)]
pub command: Commands, pub command: Commands,
@@ -43,3 +45,23 @@ pub enum Commands {
shell: Shell, shell: Shell,
}, },
} }
// clap styles headers bold by default but adds no colour
fn help_styles() -> Styles {
Styles::styled()
.header(AnsiColor::Green.on_default() | Effects::BOLD)
.usage(AnsiColor::Green.on_default() | Effects::BOLD)
.literal(AnsiColor::Cyan.on_default() | Effects::BOLD)
.placeholder(AnsiColor::Cyan.on_default())
}
#[cfg(test)]
mod tests {
use super::Ahab;
use clap::CommandFactory;
#[test]
fn the_command_is_well_formed() {
Ahab::command().debug_assert();
}
}