use clap::{Args, Subcommand, ValueEnum, ValueHint};
use strum::Display;
use url::Url;
use crate::cli::commands::output::OutputArgs;
#[derive(Args, Debug)]
pub struct GitHubArgs {
#[command(subcommand)]
pub command: GitHubCommand,
#[arg(global = true, long, default_value = "https://api.github.com/", value_hint = ValueHint::Url)]
pub github_api_url: Url,
}
#[derive(Subcommand, Debug)]
pub enum GitHubCommand {
#[command(subcommand)]
Repos(GitHubReposCommand),
}
#[derive(Subcommand, Debug)]
pub enum GitHubReposCommand {
List(GitHubReposListArgs),
}
#[derive(Args, Debug, Clone)]
pub struct GitHubReposListArgs {
#[command(flatten)]
pub repo_specifiers: GitHubRepoSpecifiers,
#[command(flatten)]
pub output_args: OutputArgs<GitHubOutputFormat>,
}
#[derive(Args, Debug, Clone)]
pub struct GitHubRepoSpecifiers {
#[arg(long, alias = "github-user")]
pub user: Vec<String>,
#[arg(long, requires = "user")]
pub include_gists: bool,
#[arg(long, alias = "org", alias = "github-organization", alias = "github-org")]
pub organization: Vec<String>,
#[arg(long = "github-exclude", alias = "github-exclude-repo", value_name = "OWNER/REPO")]
pub exclude_repos: Vec<String>,
#[arg(
long,
alias = "all-orgs",
alias = "all-github-organizations",
alias = "all-github-orgs",
requires = "api_url"
)]
pub all_organizations: bool,
#[arg(long, default_value_t = GitHubRepoType::Source, alias = "github-repo-type")]
pub repo_type: GitHubRepoType,
}
impl GitHubRepoSpecifiers {
pub fn is_empty(&self) -> bool {
self.user.is_empty() && self.organization.is_empty() && !self.all_organizations
}
}
#[derive(Copy, Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
#[strum(serialize_all = "kebab-case")]
pub enum GitHubRepoType {
Source,
#[value(alias = "forks")]
Fork,
All,
}
impl From<GitHubRepoType> for crate::github::RepoType {
fn from(val: GitHubRepoType) -> Self {
match val {
GitHubRepoType::Source => crate::github::RepoType::Source,
GitHubRepoType::Fork => crate::github::RepoType::Fork,
GitHubRepoType::All => crate::github::RepoType::All,
}
}
}
#[derive(Copy, Clone, Debug, ValueEnum, Display)]
#[strum(serialize_all = "kebab-case")]
pub enum GitHubOutputFormat {
Pretty,
Json,
Jsonl,
Bson,
Sarif,
}
#[derive(Copy, Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
#[strum(serialize_all = "kebab-case")]
pub enum GitCloneMode {
Bare,
Mirror,
}
#[derive(Copy, Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
#[strum(serialize_all = "kebab-case")]
pub enum GitHistoryMode {
Full,
None,
}