use anyhow::Result;
use clap::{Parser, Subcommand};
use colored::*;
mod commands;
mod config;
mod git;
mod utils;
mod workflows;
#[derive(Parser)]
#[command(
name = "gwf",
version,
author,
about = "Git Workflow Automator - Streamline your Git workflows",
long_about = None
)]
pub struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
#[arg(short, long)]
quiet: bool,
}
#[derive(Subcommand)]
enum Commands {
Init {
#[arg(short, long)]
force: bool,
},
Feature {
name: String,
#[arg(short, long)]
from: Option<String>,
#[arg(short, long)]
push: bool,
},
Hotfix {
name: String,
#[arg(short, long)]
target: Option<String>,
},
Release {
version: String,
#[arg(short, long)]
changelog: bool,
#[arg(short, long)]
tag: bool,
},
Sync {
#[arg(short, long)]
all: bool,
#[arg(short, long)]
branch: Option<String>,
},
Cleanup {
#[arg(short, long)]
yes: bool,
#[arg(short, long)]
dry_run: bool,
#[arg(short, long)]
remote: bool,
},
Commit {
message: Option<String>,
#[arg(short, long)]
ai: bool,
#[arg(long)]
amend: bool,
},
#[command(name = "pr")]
PullRequest {
title: Option<String>,
#[arg(short, long)]
target: Option<String>,
#[arg(short, long)]
draft: bool,
},
Standup {
#[arg(short, long, default_value = "1")]
days: u32,
#[arg(short, long)]
all: bool,
},
Config {
#[arg(short, long)]
show: bool,
#[arg(short, long)]
edit: bool,
#[arg(short, long)]
reset: bool,
},
Completions {
shell: clap_complete::Shell,
},
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let log_level = match cli.verbose {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
};
if !cli.quiet {
tracing_subscriber::fmt().with_env_filter(log_level).init();
}
if !cli.quiet && cli.verbose == 0 {
println!(
"{}",
r#"
_____ _ _________
/ ____| | / ____/ __|
| | __| | /| / / /_ | |_
| | |_ | |/ |/ / ___|| _|
| |__| |__/|__/ / | |
\_____\__/\__/_/ |_|
"#
.bright_cyan()
);
println!("{}\n", "Git Workflow Automator".bright_white().bold());
}
match cli.command {
Commands::Init { force } => {
commands::init::execute(force).await?;
}
Commands::Feature { name, from, push } => {
commands::feature::execute(name, from, push).await?;
}
Commands::Hotfix { name, target } => {
commands::hotfix::execute(name, target).await?;
}
Commands::Release {
version,
changelog,
tag,
} => {
commands::release::execute(version, changelog, tag).await?;
}
Commands::Sync { all, branch } => {
commands::sync::execute(all, branch).await?;
}
Commands::Cleanup {
yes,
dry_run,
remote,
} => {
commands::cleanup::execute(yes, dry_run, remote).await?;
}
Commands::Commit { message, ai, amend } => {
commands::commit::execute(message, ai, amend).await?;
}
Commands::PullRequest {
title,
target,
draft,
} => {
commands::pr::execute(title, target, draft).await?;
}
Commands::Standup { days, all } => {
commands::standup::execute(days, all).await?;
}
Commands::Config { show, edit, reset } => {
commands::config::execute(show, edit, reset).await?;
}
Commands::Completions { shell } => {
commands::completions::execute(shell);
}
}
Ok(())
}