1use crate::usage_spec;
2use clap::{Parser, Subcommand};
3use miette::Result;
4
5mod complete_word;
6mod exec;
7pub(crate) mod generate;
8mod lint;
9mod mcp;
10mod shell;
11mod sponsors;
12
13#[derive(Parser)]
14#[clap(author, version, about)]
15pub struct Cli {
16 #[clap(subcommand)]
17 command: Command,
18
19 completions: Option<String>,
21
22 #[clap(long)]
24 usage_spec: bool,
25}
26
27#[derive(Subcommand)]
28enum Command {
29 #[clap(about = "Execute a shell script using bash")]
30 Bash(shell::Shell),
31 CompleteWord(complete_word::CompleteWord),
32 Exec(exec::Exec),
33 #[clap(about = "Execute a shell script using fish")]
34 Fish(shell::Shell),
35 Generate(generate::Generate),
36 Lint(lint::Lint),
37 Mcp(mcp::Mcp),
38 #[clap(name = "powershell", about = "Execute a shell script using PowerShell")]
39 PowerShell(shell::Shell),
40 Sponsors(sponsors::Sponsors),
41 #[clap(about = "Execute a shell script using zsh")]
42 Zsh(shell::Shell),
43}
44
45impl Cli {
46 pub fn run(argv: &[String]) -> Result<()> {
47 let cli = Self::parse_from(argv);
48 if cli.usage_spec {
49 return usage_spec::generate();
50 }
51 match cli.command {
52 Command::Bash(mut cmd) => cmd.run("bash"),
53 Command::Fish(mut cmd) => cmd.run("fish"),
54 Command::PowerShell(mut cmd) => cmd.run("pwsh"),
55 Command::Zsh(mut cmd) => cmd.run("zsh"),
56 Command::Generate(cmd) => cmd.run(),
57 Command::Exec(mut cmd) => cmd.run(),
58 Command::CompleteWord(cmd) => cmd.run(),
59 Command::Lint(cmd) => cmd.run(),
60 Command::Mcp(cmd) => cmd.run(),
61 Command::Sponsors(cmd) => cmd.run(),
62 }
63 }
64}