use anyhow::Result;
use clap::{Parser, Subcommand};
pub mod commands;
pub mod database;
pub mod git;
pub mod validate;
use commands::*;
#[derive(Parser, Debug)]
#[command(name = "adof")]
#[command(version = "v0.12.0")]
#[command(author = "Abinash S. <fnabinash@gmail.com>")]
#[command(about = "ADOF - An Automatic Dot-files Organizer Friend", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
Init,
Add,
Remove,
List,
Link {
link: String,
},
Push,
Update {
#[arg(short, long, default_value = "false")]
check: bool,
},
Log {
#[arg(default_value = "0")]
num: u8,
#[arg(short, long, default_value = "false")]
remote: bool,
},
Deploy {
#[arg(default_value = "")]
link: String,
#[arg(short, long, default_value = "")]
commit: String,
},
Unlink,
Uninstall,
Sponsor,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match &cli.command {
Commands::Init => {
init::init().await?;
}
Commands::Add => {
add::add().await?;
}
Commands::Remove => {
remove::remove()?;
}
Commands::List => {
list::list()?;
}
Commands::Link { link } => {
validate::github_repo(link).await?;
link::link(link)?;
}
Commands::Push => {
push::push()?;
}
Commands::Update { check } => {
update::update(*check)?;
}
Commands::Log { num, remote } => {
validate::log_counts(*num)?;
log::log(*num, *remote)?;
}
Commands::Deploy { link, commit } => {
if !link.is_empty() {
validate::github_repo(link).await?;
}
deploy::deploy(link, commit)?;
}
Commands::Unlink => {
unlink::unlink()?;
}
Commands::Uninstall => {
uninstall::uninstall()?;
}
Commands::Sponsor => {
webbrowser::open("https://github.com/sponsors/fnabinash").unwrap();
}
};
Ok(())
}