use anyhow::Result;
use clap::{Parser, Subcommand};
use jj_ryu::types::Platform;
use std::path::PathBuf;
mod cli;
#[derive(Parser)]
#[command(name = "ryu")]
#[command(about = "Stacked PRs for Jujutsu - GitHub & GitLab")]
#[command(version)]
struct Cli {
#[arg(short, long, global = true)]
path: Option<PathBuf>,
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Submit {
bookmark: String,
#[arg(long)]
dry_run: bool,
#[arg(long, short = 'c')]
confirm: bool,
#[arg(long, group = "scope")]
upto: Option<String>,
#[arg(long, group = "scope")]
only: bool,
#[arg(long)]
update_only: bool,
#[arg(long, short = 's', group = "scope")]
stack: bool,
#[arg(long)]
draft: bool,
#[arg(long)]
publish: bool,
#[arg(long, short = 'i')]
select: bool,
#[arg(long)]
remote: Option<String>,
},
Sync {
#[arg(long)]
dry_run: bool,
#[arg(long, short = 'c')]
confirm: bool,
#[arg(long)]
stack: Option<String>,
#[arg(long)]
remote: Option<String>,
},
Auth {
#[command(subcommand)]
platform: AuthPlatform,
},
}
#[derive(Subcommand)]
enum AuthPlatform {
Github {
#[command(subcommand)]
action: AuthAction,
},
Gitlab {
#[command(subcommand)]
action: AuthAction,
},
}
#[derive(Subcommand)]
enum AuthAction {
Test,
Setup,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let path = cli.path.unwrap_or_else(|| PathBuf::from("."));
match cli.command {
None => {
cli::run_analyze(&path).await?;
}
Some(Commands::Submit {
bookmark,
dry_run,
confirm,
upto,
only,
update_only,
stack,
draft,
publish,
select,
remote,
}) => {
#[allow(clippy::option_if_let_else)]
let (scope, upto_bookmark) = if let Some(ref upto_bm) = upto {
(cli::SubmitScope::Upto, Some(upto_bm.as_str()))
} else if only {
(cli::SubmitScope::Only, None)
} else if stack {
(cli::SubmitScope::Stack, None)
} else {
(cli::SubmitScope::Default, None)
};
cli::run_submit(
&path,
&bookmark,
remote.as_deref(),
cli::SubmitOptions {
dry_run,
confirm,
scope,
upto_bookmark,
update_only,
draft,
publish,
select,
},
)
.await?;
}
Some(Commands::Sync {
dry_run,
confirm,
stack,
remote,
}) => {
cli::run_sync(
&path,
remote.as_deref(),
cli::SyncOptions {
dry_run,
confirm,
stack: stack.as_deref(),
},
)
.await?;
}
Some(Commands::Auth { platform }) => match platform {
AuthPlatform::Github { action } => {
let action_str = match action {
AuthAction::Test => "test",
AuthAction::Setup => "setup",
};
cli::run_auth(Platform::GitHub, action_str).await?;
}
AuthPlatform::Gitlab { action } => {
let action_str = match action {
AuthAction::Test => "test",
AuthAction::Setup => "setup",
};
cli::run_auth(Platform::GitLab, action_str).await?;
}
},
}
Ok(())
}