84 lines
2.6 KiB
Rust
84 lines
2.6 KiB
Rust
use std::process::ExitCode;
|
|
|
|
use ahab::{cli, command_builder, scripts};
|
|
|
|
use anyhow::Result;
|
|
use clap::Parser;
|
|
|
|
fn main() -> ExitCode {
|
|
let args = cli::Ahab::parse();
|
|
|
|
command_builder::set_options(command_builder::Options {
|
|
verbose: args.verbose,
|
|
dry_run: args.dry_run,
|
|
});
|
|
|
|
if args.dry_run {
|
|
cli::reject_unsupported_dry_run(&args.command);
|
|
}
|
|
|
|
match run(args.command) {
|
|
Ok(code) => code,
|
|
Err(e) => {
|
|
eprintln!("Error: {e:#}");
|
|
ExitCode::FAILURE
|
|
}
|
|
}
|
|
}
|
|
|
|
fn run(command: cli::Commands) -> Result<ExitCode> {
|
|
let done = ExitCode::SUCCESS;
|
|
|
|
match command {
|
|
cli::Commands::Django { command } => {
|
|
match command {
|
|
cli::Django::Bash => scripts::django::bash(),
|
|
cli::Django::Run { rest } => scripts::django::run(&rest),
|
|
cli::Django::MakeCommand { app, name } => {
|
|
scripts::django::make_command(&app, &name)
|
|
}
|
|
cli::Django::Makemigrations => scripts::django::makemigrations(),
|
|
cli::Django::Manage { rest } => scripts::django::manage(&rest),
|
|
cli::Django::Migrate { rest } => scripts::django::migrate(&rest),
|
|
cli::Django::Shell => scripts::django::shell(),
|
|
cli::Django::Test => scripts::django::test(),
|
|
}?;
|
|
|
|
Ok(done)
|
|
}
|
|
cli::Commands::Postgres { command } => {
|
|
match command {
|
|
cli::Postgres::Import { path } => scripts::postgres::import(&path),
|
|
cli::Postgres::Dump { path, format, gzip } => {
|
|
scripts::postgres::dump(&path, format, gzip)
|
|
}
|
|
}?;
|
|
|
|
Ok(done)
|
|
}
|
|
cli::Commands::Link { command } => match command {
|
|
cli::Link::Add {
|
|
paths,
|
|
force,
|
|
store,
|
|
} => scripts::link::add(&paths, force, store.root.as_deref()).map(|()| done),
|
|
cli::Link::Restore { paths, all, store } => {
|
|
scripts::link::restore(&paths, all, store.root.as_deref()).map(|()| done)
|
|
}
|
|
// the one command with something to say through its exit code
|
|
cli::Link::Check {
|
|
paths,
|
|
porcelain,
|
|
null,
|
|
exit_code,
|
|
store,
|
|
} => scripts::link::check(&paths, porcelain, null, exit_code, store.root.as_deref()),
|
|
},
|
|
cli::Commands::Completions { shell } => {
|
|
scripts::completions::completions(shell)?;
|
|
|
|
Ok(done)
|
|
}
|
|
}
|
|
}
|