use clap::{Parser, Subcommand};
use git_github::{focus, llm, open};
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[arg(short, long, action = clap::ArgAction::Count)]
debug: u8,
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand, Debug)]
enum Commands {
Open {
#[clap(short, long, value_parser, conflicts_with_all = &["branch"])]
commit: Option<String>,
#[clap(short, long, value_parser)]
branch: Option<String>,
#[clap(short, long, value_parser, default_value = "origin")]
remote: String,
},
Issue {
#[command(subcommand)]
issue_command: IssueCommands,
},
Commit {
#[clap(short = 'a', long)]
auto: bool,
#[clap(short = 'm', long)]
message: bool,
},
}
#[derive(Subcommand, Debug)]
enum IssueCommands {
Focus {
#[clap(short, long, value_parser)]
issue_id: i64,
},
List,
}
fn main() {
let cli = Cli::parse();
if let Some(command) = &cli.command {
match command {
Commands::Open {
commit,
branch,
remote,
} => {
if let Some(commit) = commit {
open::open(remote, open::OpenTarget::Commit(commit.to_string()));
} else if let Some(branch) = branch {
open::open(remote, open::OpenTarget::Branch(branch.to_string()));
} else {
open::open(remote, open::OpenTarget::Remote);
}
}
Commands::Issue {
issue_command: focus_command,
} => match focus_command {
IssueCommands::Focus { issue_id } => {
println!("Focusing on issue {}", issue_id);
}
IssueCommands::List => {
println!("Listing all issues...");
let _ = focus::list_issues("origin");
}
},
Commands::Commit { auto, message } => {
if *message {
if let Err(msg) = llm::ai_commit_with_editor() {
eprint!("{:?}", msg);
}
} else if *auto {
if let Err(msg) = llm::ai_commit(true) {
eprint!("{:?}", msg);
}
} else {
eprintln!("Error: Please specify either -a (auto) or -m (message) flag");
}
}
}
}
}