use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; use gix_discover::repository::Path; #[derive(Debug, Parser)] #[command(version, about)] #[command(propagate_version = true)] pub struct Cli { #[command(flatten)] pub global_opts: GlobalOpts, #[command(subcommand)] pub command: Commands, } fn path_is_repo(path: &str) -> Result { let path = PathBuf::from(path); let (repo, _trust) = gix_discover::upwards(&path).map_err(|err| err.to_string())?; let work_dir = match repo { Path::LinkedWorkTree { work_dir, .. } => work_dir, Path::WorkTree(work_dir) => work_dir, Path::Repository(git_dir) => { return Err(format!( "Repo '{}' has no working directory", git_dir.to_string_lossy() )); } }; Ok(work_dir) } #[derive(Debug, Args)] pub struct GlobalOpts { #[arg(global = true, short, long, action = clap::ArgAction::Count)] /// Use verbose output pub verbose: u8, #[arg(global = true, short, long, value_parser = path_is_repo, default_value_os_t = PathBuf::from("."))] /// Path to the repo containing the config files pub repo: PathBuf, } #[derive(Debug, Subcommand)] pub enum Commands { /// Generate talos config file Generate, /// Generate completions for your current shell ShellCompletions, }