1mod amend;
4mod check;
5mod create_pr;
6mod info;
7mod twiddle;
8mod view;
9
10pub use amend::AmendCommand;
11pub use check::CheckCommand;
12pub use create_pr::{CreatePrCommand, PrContent};
13pub use info::InfoCommand;
14pub use twiddle::TwiddleCommand;
15pub use view::ViewCommand;
16
17use anyhow::{Context, Result};
18use clap::{Parser, Subcommand};
19
20pub(crate) fn parse_beta_header(s: &str) -> Result<(String, String)> {
22 let (k, v) = s.split_once(':').ok_or_else(|| {
23 anyhow::anyhow!("Invalid --beta-header format '{}'. Expected key:value", s)
24 })?;
25 Ok((k.to_string(), v.to_string()))
26}
27
28#[derive(Parser)]
30pub struct GitCommand {
31 #[command(subcommand)]
33 pub command: GitSubcommands,
34}
35
36#[derive(Subcommand)]
38pub enum GitSubcommands {
39 Commit(CommitCommand),
41 Branch(BranchCommand),
43}
44
45#[derive(Parser)]
47pub struct CommitCommand {
48 #[command(subcommand)]
50 pub command: CommitSubcommands,
51}
52
53#[derive(Subcommand)]
55pub enum CommitSubcommands {
56 Message(MessageCommand),
58}
59
60#[derive(Parser)]
62pub struct MessageCommand {
63 #[command(subcommand)]
65 pub command: MessageSubcommands,
66}
67
68#[derive(Subcommand)]
70pub enum MessageSubcommands {
71 View(ViewCommand),
73 Amend(AmendCommand),
75 Twiddle(TwiddleCommand),
77 Check(CheckCommand),
79}
80
81#[derive(Parser)]
83pub struct BranchCommand {
84 #[command(subcommand)]
86 pub command: BranchSubcommands,
87}
88
89#[derive(Subcommand)]
91pub enum BranchSubcommands {
92 Info(InfoCommand),
94 Create(CreateCommand),
96}
97
98#[derive(Parser)]
100pub struct CreateCommand {
101 #[command(subcommand)]
103 pub command: CreateSubcommands,
104}
105
106#[derive(Subcommand)]
108pub enum CreateSubcommands {
109 Pr(CreatePrCommand),
111}
112
113impl GitCommand {
114 pub fn execute(self) -> Result<()> {
116 match self.command {
117 GitSubcommands::Commit(commit_cmd) => commit_cmd.execute(),
118 GitSubcommands::Branch(branch_cmd) => branch_cmd.execute(),
119 }
120 }
121}
122
123impl CommitCommand {
124 pub fn execute(self) -> Result<()> {
126 match self.command {
127 CommitSubcommands::Message(message_cmd) => message_cmd.execute(),
128 }
129 }
130}
131
132impl MessageCommand {
133 pub fn execute(self) -> Result<()> {
135 match self.command {
136 MessageSubcommands::View(view_cmd) => view_cmd.execute(),
137 MessageSubcommands::Amend(amend_cmd) => amend_cmd.execute(),
138 MessageSubcommands::Twiddle(twiddle_cmd) => {
139 let rt =
141 tokio::runtime::Runtime::new().context("Failed to create tokio runtime")?;
142 rt.block_on(twiddle_cmd.execute())
143 }
144 MessageSubcommands::Check(check_cmd) => {
145 let rt =
147 tokio::runtime::Runtime::new().context("Failed to create tokio runtime")?;
148 rt.block_on(check_cmd.execute())
149 }
150 }
151 }
152}
153
154impl BranchCommand {
155 pub fn execute(self) -> Result<()> {
157 match self.command {
158 BranchSubcommands::Info(info_cmd) => info_cmd.execute(),
159 BranchSubcommands::Create(create_cmd) => {
160 let rt = tokio::runtime::Runtime::new()
162 .context("Failed to create tokio runtime for PR creation")?;
163 rt.block_on(create_cmd.execute())
164 }
165 }
166 }
167}
168
169impl CreateCommand {
170 pub async fn execute(self) -> Result<()> {
172 match self.command {
173 CreateSubcommands::Pr(pr_cmd) => pr_cmd.execute().await,
174 }
175 }
176}