From e3306c494d5b4c114489021ef37fa6ea1a2755ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Fri, 2 Jun 2023 17:12:57 +0200 Subject: [PATCH] feat: prepulate command in make-command Fixed bug where created command file didn't end with `.py` and prepopulate created file with minimal example of django management command. --- src/scripts/django.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/scripts/django.rs b/src/scripts/django.rs index c9d3410..5cc01c8 100644 --- a/src/scripts/django.rs +++ b/src/scripts/django.rs @@ -4,6 +4,7 @@ use super::DockerCommand; use anyhow::{anyhow, Result}; use std::env; use std::fs::create_dir; +use std::io::Write; use std::path::{Path, PathBuf}; fn get_django_settings_module() -> Result { @@ -13,6 +14,14 @@ fn get_django_settings_module() -> Result { Ok(dsm) } +const DEBUG_TEMPLATE: &str = r#"from django.core.management.base import BaseCommand + +class Command(BaseCommand): + def handle(self, *args, **options): + pass + +"#; + pub fn make_command(app: &PathBuf, name: &str) -> Result<()> { let app_name = app.to_string_lossy(); let app_dir = Path::new(&app); @@ -44,7 +53,9 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> { println!("created module {app_name}.management.commands") }; - safe_create_file(commands_dir.join(name))?; + let mut file = safe_create_file(commands_dir.join(format!("{name}.py")))?; + file.write_all(DEBUG_TEMPLATE.as_bytes())?; + println!("created command {app_name}.management.commands.{name}"); Ok(()) }