use anyhow::Result;
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
fn main() -> Result<()> {
clap_complete::CompleteEnv::with_factory(Cli::command).complete();
let cli = Cli::parse();
match cli.command {
Some(Commands::Completions { shell }) => {
let mut command = Cli::command();
let bin_name = command.get_name().to_string();
clap_complete::generate(shell, &mut command, bin_name, &mut std::io::stdout());
}
None => {
Cli::command().print_help()?;
println!();
}
}
Ok(())
}
#[derive(Debug, Parser)]
#[command(
name = "koban",
version,
about = "Invoice Ninja from the terminal",
long_about = "koban is a Rust CLI for Invoice Ninja, designed for both humans and AI agents.",
arg_required_else_help = true
)]
struct Cli {
#[arg(long, value_enum, default_value_t = OutputFormat::Table, global = true)]
output: OutputFormat,
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
enum OutputFormat {
Table,
Json,
}
#[derive(Debug, Subcommand)]
enum Commands {
#[command(after_long_help = "\
Setup examples:
zsh:
source <(koban completions zsh)
bash:
source <(koban completions bash)
fish:
koban completions fish | source")]
Completions {
#[arg(value_enum)]
shell: Shell,
},
}