pub mod api;
pub mod auth;
pub mod config;
pub mod issue;
pub mod label;
pub mod milestone;
pub mod notification;
pub mod pull_request;
pub mod repo;
pub mod user;
mod text_manipulation;
use clap::{CommandFactory, Parser};
use clap_complete::Shell;
#[derive(Debug, clap::Parser)]
#[command(version)]
pub struct BergCommand {
#[command(subcommand)]
pub sub: BergActions,
#[arg(
long,
help = [
"Whether or not to disable all interactive features.",
"In this case arguments have to be provided in the console!",
""
].join("\n")
)]
pub non_interactive: bool,
}
pub struct GeneralArgs {
pub non_interactive: bool,
}
impl BergCommand {
pub fn generate_completion(shell: Shell) -> anyhow::Result<()> {
clap_complete::generate(
shell,
&mut BergCommand::command(),
"berg",
&mut std::io::stdout(),
);
Ok(())
}
pub async fn run(self) -> anyhow::Result<()> {
let general_args = GeneralArgs {
non_interactive: self.non_interactive,
};
match self.sub {
BergActions::API(args) => args.run(general_args).await,
BergActions::Auth(args) => args.run(general_args).await,
BergActions::Config(args) => args.run(general_args).await,
BergActions::User(args) => args.run(general_args).await,
BergActions::Issue(args) => args.run(general_args).await,
BergActions::Pull(args) => args.run(general_args).await,
BergActions::Label(args) => args.run(general_args).await,
BergActions::Repo(args) => args.run(general_args).await,
BergActions::Milestone(args) => args.run(general_args).await,
BergActions::Notification(args) => args.run(general_args).await,
BergActions::Completion { shell } => Self::generate_completion(shell),
}
}
}
#[derive(Parser, Debug)]
pub enum BergActions {
#[command(subcommand)]
API(api::ApiArgs),
#[command(subcommand)]
Auth(auth::AuthArgs),
#[command(subcommand)]
Config(config::ConfigArgs),
#[command(subcommand)]
User(user::UserArgs),
#[command(subcommand)]
Issue(issue::IssueArgs),
#[command(subcommand)]
Pull(pull_request::PullRequestArgs),
#[command(subcommand)]
Label(label::LabelArgs),
#[command(subcommand)]
Repo(repo::RepoArgs),
#[command(subcommand)]
Milestone(milestone::MilestoneArgs),
#[command(subcommand)]
Notification(notification::NotificationArgs),
Completion {
shell: Shell,
},
}