use clap::{Args, Parser, Subcommand};
use pji::app::PjiApp;
#[derive(Debug, Parser)]
#[command(name = "pji")]
#[command(version, about = "A CLI for managing, finding, and opening Git repositories.", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Debug, Subcommand)]
enum Commands {
Config,
Add {
git: String,
},
Remove {
git: String,
},
List {
#[arg(short, long)]
long: bool,
},
Find { query: Option<String> },
Scan,
Clean,
Open(OpenArgs),
}
#[derive(Debug, Args)]
#[command(flatten_help = true)]
struct OpenArgs {
#[command(subcommand)]
command: Option<OpenCommands>,
#[command(flatten)]
home: OpenHomeArgs,
}
#[derive(Debug, Subcommand)]
enum OpenCommands {
Home(OpenHomeArgs),
PR {
number: Option<u32>,
},
Issue {
number: Option<u32>,
},
}
#[derive(Debug, Args)]
struct OpenHomeArgs {
url: Option<String>,
}
fn main() {
let cli = Cli::parse();
match cli.command {
Some(command) => match command {
Commands::Config => {
PjiApp::new().start_config();
}
Commands::Add { git } => {
PjiApp::new().add(git.as_str());
}
Commands::Remove { git } => {
PjiApp::new().remove(git.as_str());
}
Commands::List { long } => {
PjiApp::new().list(long);
}
Commands::Find { query } => {
PjiApp::new().find(query.as_deref().unwrap_or(""));
}
Commands::Scan => {
PjiApp::new().scan();
}
Commands::Clean => PjiApp::clean(),
Commands::Open(args) => {
let open_cmd = args.command.unwrap_or(OpenCommands::Home(args.home));
match open_cmd {
OpenCommands::Home(home) => {
PjiApp::new().open_home(home.url);
}
OpenCommands::PR { number } => {
PjiApp::new().open_pr(number);
}
OpenCommands::Issue { number } => {
PjiApp::new().open_issue(number);
}
}
}
},
None => {
println!("No command provided");
}
}
}