refactor: pass invocation options down instead of reading a global

This commit is contained in:
2026-09-08 11:29:33 +00:00
parent 056da8b9b2
commit 3d06f7dcb0
7 changed files with 109 additions and 112 deletions

View File

@@ -3,24 +3,27 @@ use std::process::ExitCode;
mod cli;
mod command_builder;
mod compose;
mod ctx;
mod scripts;
use anyhow::Result;
use clap::Parser;
use crate::ctx::Ctx;
fn main() -> ExitCode {
let args = cli::Ahab::parse();
command_builder::set_options(command_builder::Options {
let ctx = Ctx {
verbose: args.verbose,
dry_run: args.dry_run,
});
};
if args.dry_run {
if ctx.dry_run {
cli::reject_unsupported_dry_run(&args.command);
}
match run(args.command) {
match run(&ctx, args.command) {
Ok(code) => code,
Err(e) => {
eprintln!("Error: {e:#}");
@@ -29,31 +32,31 @@ fn main() -> ExitCode {
}
}
fn run(command: cli::Commands) -> Result<ExitCode> {
fn run(ctx: &Ctx, 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::Bash => scripts::django::bash(ctx),
cli::Django::Run { rest } => scripts::django::run(ctx, &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(),
cli::Django::Makemigrations => scripts::django::makemigrations(ctx),
cli::Django::Manage { rest } => scripts::django::manage(ctx, &rest),
cli::Django::Migrate { rest } => scripts::django::migrate(ctx, &rest),
cli::Django::Shell => scripts::django::shell(ctx),
cli::Django::Test => scripts::django::test(ctx),
}?;
Ok(done)
}
cli::Commands::Postgres { command } => {
match command {
cli::Postgres::Import { path } => scripts::postgres::import(&path),
cli::Postgres::Import { path } => scripts::postgres::import(ctx, &path),
cli::Postgres::Dump { path, format, gzip } => {
scripts::postgres::dump(&path, format, gzip)
scripts::postgres::dump(ctx, &path, format, gzip)
}
}?;