worm_hole 2.0.0

CLI tool to easily jump between directories
// Copyright (C) 2025 Rignchen
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

pub mod alias;
pub mod cli;
pub mod commands;
pub mod db;
pub mod error;
pub mod path;

use cli::{Args, Command};
use db::Database;
use error::{unwrap_worm_hole_error, WHResult};

fn main() {
	unwrap_worm_hole_error(run());
}

fn run() -> WHResult<()> {
	let args = Args::parse_args();
	let database = Database::new(args.db_path.as_str())?;

	match args.cmd {
		Command::AddAlias(add) => {
			add.run(&database)?;
		}
		Command::RemoveAlias(remove) => {
			remove.run(&database)?;
		}
		Command::ListAliases(list) => {
			list.run(&database)?;
		}
		Command::SearchAliases(search) => {
			search.run(&database)?;
		}
		Command::Query(query) => {
			query.run(&database)?;
		}
		Command::EditAlias(edit) => {
			edit.run(&database)?;
		}
		Command::RenameAlias(rename) => {
			rename.run(&database)?;
		}
		Command::Init(init) => {
			init.run(&database, args.db_path.as_str())?;
		}
	}

	Ok(())
}