use clap::{Args as ClapArgs, Subcommand};
use crate::{
cli::CliResult,
core::{branch, context::Context},
};
#[derive(Debug, Clone, ClapArgs)]
#[command(about = "List, switch, create and prune branches")]
pub struct Args {
#[command(subcommand)]
pub subcommand: Option<BranchSubcommand>,
}
#[derive(Debug, Clone, Subcommand)]
pub enum BranchSubcommand {
List {
#[arg(long, short = 'r', conflicts_with = "all")]
remote: bool,
#[arg(long, short = 'a')]
all: bool,
},
Switch {
name: Option<String>,
},
New {
name: Option<String>,
#[arg(long, short = 'd', conflicts_with = "name")]
description: Option<String>,
#[arg(long = "type", short = 't')]
kind: Option<String>,
#[arg(long, short = 'T')]
ticket: Option<String>,
#[arg(long)]
from: Option<String>,
#[arg(long)]
no_switch: bool,
},
Prune {
#[arg(long)]
force: bool,
#[arg(long)]
no_fetch: bool,
#[arg(long)]
merged: bool,
#[arg(long)]
remote: bool,
},
}
pub async fn run(ctx: &Context, args: Args) -> CliResult<()> {
match args.subcommand {
Some(BranchSubcommand::List { remote, all }) => branch::list::run(ctx, remote, all),
Some(BranchSubcommand::Switch { name }) => branch::switch::run(ctx, name),
Some(BranchSubcommand::New {
name,
description,
kind,
ticket,
from,
no_switch,
}) => branch::create::run(
ctx,
branch::create::Options {
name,
description,
kind,
ticket,
from,
no_switch,
},
),
Some(BranchSubcommand::Prune {
force,
no_fetch,
merged,
remote,
}) => branch::prune::run(
ctx,
branch::prune::Options {
force,
no_fetch,
merged,
remote,
},
),
None if ctx.is_interactive() => branch::switch::run(ctx, None),
None => branch::list::run(ctx, false, false),
}
}