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.
This commit is contained in:
		@@ -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<String> {
 | 
			
		||||
@@ -13,6 +14,14 @@ fn get_django_settings_module() -> Result<String> {
 | 
			
		||||
    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(())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user