codeberg_cli/actions/
mod.rs1pub mod api;
2pub mod auth;
3pub mod config;
4pub mod issue;
5pub mod label;
6pub mod milestone;
7pub mod notification;
8pub mod pull_request;
9pub mod release;
10pub mod repo;
11pub mod user;
12
13mod text_manipulation;
15
16use clap::{CommandFactory, Parser};
17use clap_complete::Shell;
18
19use crate::types::output::OutputMode;
20
21#[derive(Debug, clap::Parser)]
22#[command(version)]
23pub struct BergCommand {
24 #[command(subcommand)]
25 pub sub: BergActions,
26
27 #[arg(value_enum, long, default_value_t = OutputMode::Pretty)]
29 pub output_mode: OutputMode,
30
31 #[arg(long)]
36 pub non_interactive: bool,
37
38 #[arg(long, short = 'w')]
51 pub max_width: Option<i32>,
52}
53
54#[derive(Debug, Clone, Copy)]
55pub struct GeneralArgs {
56 pub non_interactive: bool,
57 pub max_width: Option<i32>,
58 pub output_mode: OutputMode,
59}
60
61impl BergCommand {
62 pub fn generate_completion(shell: Shell) -> anyhow::Result<()> {
63 clap_complete::generate(
64 shell,
65 &mut BergCommand::command(),
66 "berg",
67 &mut std::io::stdout(),
68 );
69 Ok(())
70 }
71
72 pub async fn run(self) -> anyhow::Result<()> {
73 let general_args = GeneralArgs {
74 non_interactive: self.non_interactive,
75 max_width: self.max_width,
76 output_mode: self.output_mode,
77 };
78 match self.sub {
79 BergActions::API(args) => args.run(general_args).await,
80 BergActions::Auth(args) => args.run(general_args).await,
81 BergActions::Config(args) => args.run(general_args).await,
82 BergActions::User(args) => args.run(general_args).await,
83 BergActions::Issue(args) => args.run(general_args).await,
84 BergActions::Pull(args) => args.run(general_args).await,
85 BergActions::Label(args) => args.run(general_args).await,
86 BergActions::Release(args) => args.run(general_args).await,
87 BergActions::Repo(args) => args.run(general_args).await,
88 BergActions::Milestone(args) => args.run(general_args).await,
89 BergActions::Notification(args) => args.run(general_args).await,
90 BergActions::Completion { shell } => Self::generate_completion(shell),
91 }
92 }
93}
94
95#[derive(Parser, Debug)]
97pub enum BergActions {
98 #[command(subcommand)]
99 API(api::ApiArgs),
100
101 #[command(subcommand)]
102 Auth(auth::AuthArgs),
103
104 #[command(subcommand)]
105 Config(config::ConfigArgs),
106
107 #[command(subcommand)]
108 User(user::UserArgs),
109
110 #[command(subcommand)]
111 Issue(issue::IssueArgs),
112
113 #[command(subcommand)]
114 Pull(pull_request::PullRequestArgs),
115
116 #[command(subcommand)]
117 Label(label::LabelArgs),
118
119 #[command(subcommand)]
120 Release(release::ReleaseArgs),
121
122 #[command(subcommand)]
123 Repo(repo::RepoArgs),
124
125 #[command(subcommand)]
126 Milestone(milestone::MilestoneArgs),
127
128 #[command(subcommand)]
129 Notification(notification::NotificationArgs),
130
131 Completion {
133 shell: Shell,
135 },
136}