use crate::errors::*;
use clap::{ArgAction, CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
use std::io;
use std::path::PathBuf;
#[derive(Debug, Parser)]
#[command(version)]
pub struct Args {
#[arg(short, long, global = true, action(ArgAction::Count))]
pub verbose: u8,
#[arg(short = 'C', long)]
pub context: Option<PathBuf>,
#[command(subcommand)]
pub subcommand: SubCommand,
}
#[derive(Debug, Subcommand)]
pub enum SubCommand {
Build(Build),
Update(Update),
Completions(Completions),
}
#[derive(Debug, Parser)]
pub struct Build {
#[arg(short, long)]
pub file: Option<PathBuf>,
#[arg(short, long)]
pub keep: bool,
#[arg(required = true)]
pub cmd: Vec<String>,
}
#[derive(Debug, Parser)]
pub struct Update {
#[arg(long)]
pub no_pull: bool,
#[arg(short, long)]
pub keep: bool,
}
#[derive(Debug, Parser)]
pub struct Completions {
pub shell: Shell,
}
impl Completions {
pub fn generate<W: io::Write>(&self, mut w: W) -> Result<()> {
clap_complete::generate(self.shell, &mut Args::command(), "repro-env", &mut w);
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_zsh_completions() {
Completions { shell: Shell::Zsh }
.generate(io::sink())
.unwrap();
}
}