use anyhow::Result;
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum};
use clap_complete::{generate, Shell};
use std::io;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct CompletionCli {
#[command(subcommand)]
command: Option<CompletionCommands>,
#[arg(short, long)]
dry_run: bool,
#[arg(short, long)]
amend: bool,
}
#[derive(Subcommand)]
enum CompletionCommands {
Auth(AuthCommands),
Completion(CompletionCommand),
Prompt(PromptCommands),
}
#[derive(Args)]
struct AuthCommands {
#[command(subcommand)]
command: AuthSubcommand,
}
#[derive(Subcommand)]
enum AuthSubcommand {
Add {
provider: String,
api_key: String,
},
Use {
provider: String,
},
Set {
property_path: String,
value: String,
},
List,
}
#[derive(Args)]
struct PromptCommands {
#[command(subcommand)]
command: PromptSubcommand,
}
#[derive(Subcommand)]
enum PromptSubcommand {
System {
prompt: String,
},
User {
prompt: String,
},
Show,
}
#[derive(Args)]
pub struct CompletionCommand {
#[arg(value_enum)]
shell: CompletionShell,
}
#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
pub enum CompletionShell {
Bash,
Zsh,
Fish,
PowerShell,
Elvish,
}
impl From<CompletionShell> for Shell {
fn from(shell: CompletionShell) -> Self {
match shell {
CompletionShell::Bash => Shell::Bash,
CompletionShell::Zsh => Shell::Zsh,
CompletionShell::Fish => Shell::Fish,
CompletionShell::PowerShell => Shell::PowerShell,
CompletionShell::Elvish => Shell::Elvish,
}
}
}
impl CompletionCommand {
pub async fn execute(&self) -> Result<()> {
let shell: Shell = self.shell.into();
let mut cmd = CompletionCli::command();
let bin_name = "fuckmit".to_string();
generate(shell, &mut cmd, bin_name, &mut io::stdout());
Ok(())
}
}