//! The Command Line Interface definition to the git-identity subcommand use std::{borrow::Cow, sync::LazyLock}; use clap::{ArgAction, Args, Parser, Subcommand}; use console::Term; use dialoguer::theme::ColorfulTheme; /// Manages multiple identities (e.g. personal, work, university, ...) in git repos for you. #[derive(Parser, Debug)] pub struct Cli { #[command(flatten)] pub global: GlobalArgs, #[command(subcommand)] pub command: Command, } impl Cli { pub fn run_subcommand(self) -> anyhow::Result<()> { match self.command { Command::Import(cli) => crate::subcommands::import::main(self.global, cli), } } } /// Global arguments (not specific to any subcommand) #[derive(Args, Debug)] pub struct GlobalArgs { /// Increases the verbosity of the log outputs /// /// The RUST_LOG environment variable takes priority if both are specified. #[arg(short, long = "verbose", action = ArgAction::Count)] pub verbosity: u8, } #[derive(Subcommand, Debug)] pub enum Command { Import(ImportCli), } #[derive(Parser, Debug)] pub struct ImportCli { /// A list of patterns to filter GPG keys with, works the same way as patterns you use with /// the gpg command #[arg(id = "PATTERN")] pub patterns: Vec>, } pub static THEME: LazyLock = LazyLock::new(|| ColorfulTheme { ..Default::default() }); pub static STDERR: LazyLock = LazyLock::new(Term::stderr);