Skip to content

Commit

Permalink
feat(lcat): colorize --help (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer authored Sep 26, 2024
1 parent e04b68f commit 66eef55
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lcat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ use std::{
path::PathBuf,
};

use clap::Parser;
use clap::{CommandFactory, Parser};
use lcat::{Rainbow, RainbowCmd};

#[derive(Parser)]
#[clap(name = "lcat", about = "Terminal rainbows.")]
#[clap(name = "lcat", about = "Terminal rainbows.", disable_help_flag = true)]
pub struct Cmdline {
#[clap(name = "File", default_value = "-")]
files: Vec<PathBuf>,

#[clap(flatten)]
rainbow: RainbowCmd,

/// Print help
#[clap(short = 'h', long)]
help: bool,
}

fn main() -> Result<(), io::Error> {
Expand All @@ -25,6 +29,14 @@ fn main() -> Result<(), io::Error> {
let mut rainbow: Rainbow = opt.rainbow.into();
let mut stdout = io::stdout().lock();

if opt.help {
rainbow.colorize_str(
&Cmdline::command().render_help().ansi().to_string(),
&mut stdout,
)?;
return Ok(());
}

for path in opt.files {
if path == PathBuf::from("-") {
let mut stdin = io::stdin().lock();
Expand Down

0 comments on commit 66eef55

Please sign in to comment.