use clap::{Args, Subcommand, ValueEnum, ValueHint};
use strum::Display;
use url::Url;
use crate::cli::commands::output::{GitHubOutputFormat, OutputArgs};
#[derive(Args, Debug)]
pub struct GitLabArgs {
#[command(subcommand)]
pub command: GitLabCommand,
#[arg(global = true, long, default_value = "https://gitlab.com/", value_hint = ValueHint::Url)]
pub gitlab_api_url: Url,
}
#[derive(Subcommand, Debug)]
pub enum GitLabCommand {
#[command(subcommand)]
Repos(GitLabReposCommand),
}
#[derive(Subcommand, Debug)]
pub enum GitLabReposCommand {
List(GitLabReposListArgs),
}
#[derive(Args, Debug, Clone)]
pub struct GitLabReposListArgs {
#[command(flatten)]
pub repo_specifiers: GitLabRepoSpecifiers,
#[command(flatten)]
pub output_args: OutputArgs<GitLabOutputFormat>,
}
#[derive(Args, Debug, Clone)]
pub struct GitLabRepoSpecifiers {
#[arg(long, alias = "gitlab-user")]
pub user: Vec<String>,
#[arg(long)]
pub include_snippets: bool,
#[arg(long, alias = "gitlab-group")]
pub group: Vec<String>,
#[arg(
long = "gitlab-exclude",
alias = "gitlab-exclude-project",
alias = "gitlab-exclude-repo",
value_name = "GROUP/PROJECT"
)]
pub exclude_repos: Vec<String>,
#[arg(long, alias = "all-groups", alias = "all-gitlab-groups", requires = "api_url")]
pub all_groups: bool,
#[arg(long, default_value_t = GitLabRepoType::All, alias = "gitlab-repo-type")]
pub repo_type: GitLabRepoType,
#[arg(long, alias = "gitlab-include-subgroups")]
pub include_subgroups: bool,
}
impl GitLabRepoSpecifiers {
pub fn is_empty(&self) -> bool {
self.user.is_empty() && self.group.is_empty() && !self.all_groups
}
}
#[derive(Copy, Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
#[strum(serialize_all = "kebab-case")]
pub enum GitLabRepoType {
All,
Owner,
Member,
}
pub type GitLabOutputFormat = GitHubOutputFormat;
impl From<GitLabRepoType> for crate::gitlab::RepoType {
fn from(val: GitLabRepoType) -> Self {
match val {
GitLabRepoType::All => crate::gitlab::RepoType::All,
GitLabRepoType::Owner => crate::gitlab::RepoType::Owner,
GitLabRepoType::Member => crate::gitlab::RepoType::Member,
}
}
}