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::builder::Styles;
17use clap::builder::styling::{AnsiColor, Effects};
18use clap::{CommandFactory, Parser};
19use clap_complete::Shell;
20
21use crate::types::{git::OwnerRepo, output::OutputMode};
22
23const STYLES: Styles = Styles::styled()
24 .header(AnsiColor::Yellow.on_default().effects(Effects::BOLD))
25 .usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
26 .literal(AnsiColor::Green.on_default().effects(Effects::BOLD))
27 .placeholder(AnsiColor::Green.on_default());
28
29#[derive(Debug, clap::Parser)]
30#[command(version, styles = STYLES)]
31pub struct BergCommand {
32 #[command(subcommand)]
33 pub sub: BergActions,
34
35 #[arg(value_enum, long, default_value_t = OutputMode::Pretty, global = true,)]
37 pub output_mode: OutputMode,
38
39 #[arg(long, global = true)]
44 pub non_interactive: bool,
45
46 #[arg(long, short = 'w', global = true)]
59 pub max_width: Option<i32>,
60
61 #[arg(long, global = true, value_name = "OWNER/REPO")]
63 pub owner_repo: Option<OwnerRepo>,
64}
65
66#[derive(Debug, Clone)]
67pub struct GlobalArgs {
68 pub non_interactive: bool,
69 pub max_width: Option<i32>,
70 pub output_mode: OutputMode,
71 pub owner_repo: Option<OwnerRepo>,
72}
73
74impl BergCommand {
75 pub fn generate_completion(shell: Shell) -> miette::Result<()> {
76 clap_complete::generate(
77 shell,
78 &mut BergCommand::command(),
79 "berg",
80 &mut std::io::stdout(),
81 );
82 Ok(())
83 }
84
85 pub async fn run(self) -> miette::Result<()> {
86 let global_args = GlobalArgs {
87 non_interactive: self.non_interactive,
88 max_width: self.max_width,
89 output_mode: self.output_mode,
90 owner_repo: self.owner_repo,
91 };
92 match self.sub {
93 BergActions::API(args) => args.run(global_args).await,
94 BergActions::Auth(args) => args.run(global_args).await,
95 BergActions::Config(args) => args.run(global_args).await,
96 BergActions::User(args) => args.run(global_args).await,
97 BergActions::Issue(args) => args.run(global_args).await,
98 BergActions::Pull(args) => args.run(global_args).await,
99 BergActions::Label(args) => args.run(global_args).await,
100 BergActions::Release(args) => args.run(global_args).await,
101 BergActions::Repo(args) => args.run(global_args).await,
102 BergActions::Milestone(args) => args.run(global_args).await,
103 BergActions::Notification(args) => args.run(global_args).await,
104 BergActions::Completion { shell } => Self::generate_completion(shell),
105 }
106 }
107}
108
109#[derive(Parser, Debug)]
111pub enum BergActions {
112 #[command(subcommand)]
113 API(api::ApiArgs),
114
115 #[command(subcommand)]
116 Auth(auth::AuthArgs),
117
118 #[command(subcommand)]
119 Config(config::ConfigArgs),
120
121 #[command(subcommand)]
122 User(user::UserArgs),
123
124 #[command(subcommand)]
125 Issue(issue::IssueArgs),
126
127 #[command(subcommand)]
128 Pull(pull_request::PullRequestArgs),
129
130 #[command(subcommand)]
131 Label(label::LabelArgs),
132
133 #[command(subcommand)]
134 Release(release::ReleaseArgs),
135
136 #[command(subcommand)]
137 Repo(repo::RepoArgs),
138
139 #[command(subcommand)]
140 Milestone(milestone::MilestoneArgs),
141
142 #[command(subcommand)]
143 Notification(notification::NotificationArgs),
144
145 Completion {
147 shell: Shell,
149 },
150}