use crate::commands;
use clap::{CommandFactory, FromArgMatches, Parser};
structstruck::strike! {
#[strikethrough[derive(Parser, Debug)]]
#[clap(verbatim_doc_comment)]
#[command(version)]
#[command(name = "worm_hole", about = "A simple CLI tool to easily navigate between directories.")]
pub struct Args {
#[clap(subcommand)]
pub cmd: pub enum Command {
Query(commands::Query),
#[clap(name = "add")]
AddAlias(commands::AddAlias),
#[clap(name = "rm")]
RemoveAlias(commands::RemoveAlias),
#[clap(name = "ls")]
ListAliases(commands::ListAliases),
#[clap(name = "search")]
SearchAliases(commands::SearchAliases),
#[clap(name = "edit")]
EditAlias(commands::EditAlias),
#[clap(name = "rename")]
RenameAlias(commands::RenameAlias),
Init(commands::Init),
},
#[clap(long, default_value_t = format!("{}/.wormhole.db", std::env::var("HOME").unwrap()))]
pub db_path: String,
}
}
impl Args {
pub fn parse_args() -> Self {
let mut command = Args::command();
let command_clone = command.clone();
command = clap_autocomplete::add_subcommand(command);
let matches = command.get_matches();
if let Some(result) = clap_autocomplete::test_subcommand(&matches, command_clone) {
if let Err(err) = result {
eprintln!("Error: {}", err);
std::process::exit(1);
} else {
std::process::exit(0);
}
}
Self::from_arg_matches(&matches).unwrap()
}
}