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

@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
use anyhow::{Result, anyhow};
use crate::compose::Compose;
use crate::ctx::Ctx;
use crate::scripts::docker_compose;
const DEBUG_TEMPLATE: &str = r#"from django.core.management.base import BaseCommand
@@ -53,40 +54,40 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> {
Ok(())
}
pub fn bash() -> Result<()> {
run(&["bash".to_string()])
pub fn bash(ctx: &Ctx) -> Result<()> {
run(ctx, &["bash".to_string()])
}
pub fn run(rest: &[String]) -> Result<()> {
let service = Compose::resolve()?.django()?;
docker_compose::run(&service, rest)
pub fn run(ctx: &Ctx, rest: &[String]) -> Result<()> {
let service = Compose::resolve(ctx)?.django()?;
docker_compose::run(ctx, &service, rest)
}
pub fn manage(rest: &[String]) -> Result<()> {
pub fn manage(ctx: &Ctx, rest: &[String]) -> Result<()> {
let mut args = vec!["python".to_string(), "manage.py".to_string()];
args.extend_from_slice(rest);
run(&args)
run(ctx, &args)
}
// shortcuts
pub fn makemigrations() -> Result<()> {
manage(&["makemigrations".to_string()])
pub fn makemigrations(ctx: &Ctx) -> Result<()> {
manage(ctx, &["makemigrations".to_string()])
}
pub fn migrate(rest: &[String]) -> Result<()> {
pub fn migrate(ctx: &Ctx, rest: &[String]) -> Result<()> {
let mut full_rest = vec!["migrate".to_string()];
full_rest.extend_from_slice(rest);
manage(&full_rest)
manage(ctx, &full_rest)
}
pub fn shell() -> Result<()> {
manage(&["shell".to_string()])
pub fn shell(ctx: &Ctx) -> Result<()> {
manage(ctx, &["shell".to_string()])
}
pub fn test() -> Result<()> {
manage(&["test".to_string()])
pub fn test(ctx: &Ctx) -> Result<()> {
manage(ctx, &["test".to_string()])
}
fn safe_create_file(path: PathBuf) -> Result<File, std::io::Error> {