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