use crate::{config::SigningFormat, report::ReportFormat};
use clap::{Args, Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
use std::path::PathBuf;
#[derive(Debug, Parser)]
#[command(
name = "gitbound",
version,
about = "Manage and verify local GitHub identities"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Profile {
#[command(subcommand)]
command: ProfileCommand,
},
Use {
profile: String,
},
Clone(CloneArgs),
Bind(BindArgs),
Unbind(RepositoryArgs),
Status(InspectArgs),
Check(InspectArgs),
Verify(InspectArgs),
Audit(AuditArgs),
Hooks {
#[command(subcommand)]
command: HooksCommand,
},
Directory {
#[command(subcommand)]
command: DirectoryCommand,
},
Doctor(DoctorArgs),
Ci {
#[command(subcommand)]
command: CiCommand,
},
Ssh {
#[command(subcommand)]
command: SshCommand,
},
Completions {
shell: Shell,
},
}
#[derive(Debug, Args)]
pub struct CloneArgs {
pub profile: String,
pub repository: String,
pub directory: Option<PathBuf>,
#[arg(long, value_enum)]
pub protocol: Option<CloneProtocol>,
#[arg(long, default_value = "origin")]
pub remote: String,
#[arg(long)]
pub no_switch: bool,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum CloneProtocol {
Ssh,
Https,
}
#[derive(Debug, Subcommand)]
pub enum ProfileCommand {
Add(ProfileMutationArgs),
Import(ProfileImportArgs),
Edit(ProfileMutationArgs),
List {
#[arg(long)]
json: bool,
},
Show {
name: String,
#[arg(long)]
json: bool,
},
Remove {
name: String,
#[arg(long)]
yes: bool,
},
Rename {
old_name: String,
new_name: String,
},
}
#[derive(Debug, Args)]
pub struct ProfileImportArgs {
pub name: String,
#[arg(long, default_value = "origin")]
pub remote: String,
#[arg(long)]
pub no_owner: bool,
#[arg(long)]
pub repo: Option<PathBuf>,
}
#[derive(Debug, Subcommand)]
pub enum DirectoryCommand {
Add {
profile: String,
path: PathBuf,
},
List {
#[arg(long)]
json: bool,
},
Sync {
profile: Option<String>,
},
Remove {
path: PathBuf,
},
}
#[derive(Debug, Args)]
pub struct ProfileMutationArgs {
pub name: String,
#[arg(long)]
pub github_user: Option<String>,
#[arg(long)]
pub git_name: Option<String>,
#[arg(long)]
pub git_email: Option<String>,
#[arg(long)]
pub hostname: Option<String>,
#[arg(long, conflicts_with = "clear_ssh_host")]
pub ssh_host: Option<String>,
#[arg(long, conflicts_with = "ssh_host")]
pub clear_ssh_host: bool,
#[arg(long)]
pub ssh_key: Option<PathBuf>,
#[arg(long = "allowed-owner")]
pub allowed_owners: Vec<String>,
#[arg(long)]
pub clear_ssh_key: bool,
#[arg(long)]
pub clear_allowed_owners: bool,
#[arg(long)]
pub signing_key: Option<String>,
#[arg(long, value_enum)]
pub signing_format: Option<SigningFormat>,
#[arg(long, conflicts_with = "no_require_signing")]
pub require_signing: bool,
#[arg(long, conflicts_with = "require_signing")]
pub no_require_signing: bool,
#[arg(long)]
pub clear_signing_key: bool,
}
#[derive(Debug, Args)]
pub struct BindArgs {
pub profile: String,
#[arg(long, default_value = "origin")]
pub remote: String,
#[arg(long, action = clap::ArgAction::SetTrue)]
pub switch: bool,
#[arg(long)]
pub force: bool,
#[arg(long)]
pub repo: Option<PathBuf>,
}
#[derive(Debug, Args)]
pub struct InspectArgs {
#[arg(long, default_value = "origin")]
pub remote: String,
#[arg(long, conflicts_with = "format")]
pub json: bool,
#[arg(long, value_enum)]
pub format: Option<ReportFormat>,
#[arg(long, value_name = "[FORMAT:]PATH")]
pub output: Vec<String>,
#[arg(long, value_name = "PATH")]
pub policy: Option<PathBuf>,
#[arg(long, conflicts_with = "policy")]
pub no_policy: bool,
#[arg(long, conflicts_with = "no_policy")]
pub require_policy: bool,
#[arg(long)]
pub offline: bool,
#[arg(long)]
pub enforce_signing: bool,
#[arg(long, value_enum, hide = true)]
pub hook: Option<HookMode>,
#[arg(long)]
pub repo: Option<PathBuf>,
}
#[derive(Debug, Args)]
pub struct AuditArgs {
#[arg(long, default_value = "HEAD")]
pub range: String,
#[arg(long, default_value_t = crate::audit::DEFAULT_MAX_COMMITS)]
pub max_commits: usize,
#[arg(long, conflicts_with = "format")]
pub json: bool,
#[arg(long, value_enum)]
pub format: Option<ReportFormat>,
#[arg(long, value_name = "[FORMAT:]PATH")]
pub output: Vec<String>,
#[arg(long, value_name = "PATH")]
pub policy: Option<PathBuf>,
#[arg(long, conflicts_with = "policy")]
pub no_policy: bool,
#[arg(long, conflicts_with = "no_policy")]
pub require_policy: bool,
#[arg(long)]
pub enforce_signing: bool,
#[arg(long)]
pub repo: Option<PathBuf>,
}
#[derive(Debug, Args)]
pub struct RepositoryArgs {
#[arg(long)]
pub repo: Option<PathBuf>,
}
#[derive(Debug, Args)]
pub struct DoctorArgs {
#[arg(long)]
pub json: bool,
}
#[derive(Debug, Subcommand)]
pub enum CiCommand {
Status {
#[arg(long, default_value_t = 5)]
limit: usize,
#[arg(long)]
json: bool,
#[arg(long)]
repo: Option<PathBuf>,
},
}
#[derive(Debug, Subcommand)]
pub enum SshCommand {
Test {
profile: String,
#[arg(long)]
json: bool,
},
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum HookMode {
PreCommit,
PrePush,
}
#[derive(Debug, Subcommand)]
pub enum HooksCommand {
Install(RepositoryArgs),
Status(RepositoryArgs),
Uninstall(RepositoryArgs),
}