refactor: put the dry-run and quiet checks on Ctx

This commit is contained in:
2026-09-09 12:32:55 +00:00
parent d9439253fd
commit b40dfe6124
10 changed files with 253 additions and 217 deletions

View File

@@ -4,7 +4,7 @@ use anyhow::{Result, anyhow};
use crate::cmd::{Bash, Cmd, Manage, Words};
use crate::ctx::Ctx;
use crate::fsops::{create_dir, touch, write_new};
use crate::output::note;
use crate::project::Project;
@@ -40,8 +40,8 @@ pub fn make_command(ctx: &Ctx, app: &Path, name: &str) -> Result<()> {
let management_dir = app_dir.join("management");
if !management_dir.exists() {
create_dir(ctx, &management_dir)?;
touch(ctx, &management_dir.join("__init__.py"))?;
ctx.fs().create_dir(&management_dir)?;
ctx.fs().touch(&management_dir.join("__init__.py"))?;
note!(ctx, "created module {app_name}.management")
};
@@ -49,14 +49,13 @@ pub fn make_command(ctx: &Ctx, app: &Path, name: &str) -> Result<()> {
let commands_dir = management_dir.join("commands");
if !commands_dir.exists() {
create_dir(ctx, &commands_dir)?;
touch(ctx, &commands_dir.join("__init__.py"))?;
ctx.fs().create_dir(&commands_dir)?;
ctx.fs().touch(&commands_dir.join("__init__.py"))?;
note!(ctx, "created module {app_name}.management.commands")
};
write_new(
ctx,
ctx.fs().write_new(
&commands_dir.join(format!("{name}.py")),
DEBUG_TEMPLATE.as_bytes(),
)?;
@@ -72,22 +71,18 @@ fn is_module_name(name: &str) -> bool {
}
pub fn bash(ctx: &Ctx) -> Result<()> {
Bash.in_service(&service(ctx)?)
.quiet(ctx.quiet)
.replace(ctx)
Bash.in_service(ctx, &service(ctx)?).replace(ctx)
}
pub fn run(ctx: &Ctx, rest: &[String]) -> Result<()> {
Words::new(rest)
.in_service(&service(ctx)?)
.quiet(ctx.quiet)
.in_service(ctx, &service(ctx)?)
.replace(ctx)
}
pub fn manage(ctx: &Ctx, rest: &[String]) -> Result<()> {
Manage::new(rest)
.in_service(&service(ctx)?)
.quiet(ctx.quiet)
.in_service(ctx, &service(ctx)?)
.replace(ctx)
}