diff --git a/src/command_builder.rs b/src/command_builder.rs index 01faca1..89a0101 100644 --- a/src/command_builder.rs +++ b/src/command_builder.rs @@ -9,7 +9,7 @@ use std::{ process::{Child, Command, Stdio}, }; -use crate::debug_println; +use crate::debug_eprintln; pub struct Args(Vec); @@ -64,7 +64,7 @@ impl CommandBuilder { } pub fn build(self) -> Result { - debug_println!("-----\n{self}\n-----"); + debug_eprintln!("-----\n{self}\n-----"); let (first, rest) = self.args.split_first().context("empty args")?; let mut command = Command::new(first); diff --git a/src/lib.rs b/src/lib.rs index ba75b2c..c24d234 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,8 @@ pub mod scripts; // NOTE: stolen from https://docs.rs/debug_print/latest/debug_print/ #[macro_export] -macro_rules! debug_println { - ($($arg:tt)*) => (if ::std::cfg!(debug_assertions) { ::std::println!($($arg)*); }) +macro_rules! debug_eprintln { + ($($arg:tt)*) => (#[cfg(debug_assertions)] eprintln!($($arg)*)); } fn safe_create_file(path: PathBuf) -> Result { diff --git a/src/scripts/django.rs b/src/scripts/django.rs index 38fe376..16cbe72 100644 --- a/src/scripts/django.rs +++ b/src/scripts/django.rs @@ -10,7 +10,7 @@ use crate::{create_file, safe_create_file}; fn get_django_settings_module() -> Result { let dsm = env::var("DJANGO_SETTINGS_MODULE")?; - println!("USING: {dsm}"); + eprintln!("USING: {dsm}"); Ok(dsm) } @@ -32,7 +32,7 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> { return Err(anyhow!("directory {app_name} does not exist")); } - println!("found app {app_name}"); + eprintln!("found app {app_name}"); let management_dir = app_dir.join("management"); @@ -41,7 +41,7 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> { create_dir(&management_dir)?; create_file(management_dir.join("__init__.py"))?; - println!("created module {app_name}.management") + eprintln!("created module {app_name}.management") }; let commands_dir = management_dir.join("commands"); @@ -51,20 +51,20 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> { create_dir(&commands_dir)?; create_file(commands_dir.join("__init__.py"))?; - println!("created module {app_name}.management.commands") + eprintln!("created module {app_name}.management.commands") }; 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}"); + eprintln!("created command {app_name}.management.commands.{name}"); Ok(()) } pub fn manage(rest: &[String]) -> Result<()> { let dsm = get_django_settings_module()?; let joined = rest.join(" "); - let command = format!("exec appserver python manage.py {joined} --settings={dsm}"); + let command = format!("run --rm appserver python manage.py {joined} --settings={dsm}"); CommandBuilder::docker_compose().args(&command).exec() } diff --git a/src/scripts/postgres.rs b/src/scripts/postgres.rs index 0153fe4..0285da1 100644 --- a/src/scripts/postgres.rs +++ b/src/scripts/postgres.rs @@ -8,7 +8,7 @@ use std::{ }; use super::docker_compose; -use crate::{command_builder::CommandBuilder, debug_println}; +use crate::{command_builder::CommandBuilder, debug_eprintln}; fn get_containers() -> Result<[String; 2]> { // get db container @@ -40,13 +40,13 @@ pub fn import(file: &Path) -> Result<()> { let [db_container, app_containers] = get_containers()?; let dump_file = file.to_string_lossy(); - println!("stopping all containers"); + eprintln!("stopping all containers"); docker_compose::stop()?; - println!("starting db container"); + eprintln!("starting db container"); docker_compose::start(Some("postgresdb"))?; - println!("restoring database"); + eprintln!("restoring database"); let commands = [ format!("cp {dump_file} {db_container}:/tmp/dbdump"), format!("exec {db_container} dropdb -U db db"), @@ -55,7 +55,7 @@ pub fn import(file: &Path) -> Result<()> { ]; for command in commands { - debug_println!("waiting until pg_isready"); + debug_eprintln!("waiting until pg_isready"); while !CommandBuilder::docker() .args(&format!( "exec {db_container} pg_isready -h postgresdb -p 5432 -U db", @@ -71,7 +71,7 @@ pub fn import(file: &Path) -> Result<()> { CommandBuilder::docker().args(&command).exec()?; } - println!("restarting containers"); + eprintln!("restarting containers"); docker_compose::stop()?; docker_compose::up()?; @@ -81,7 +81,7 @@ pub fn import(file: &Path) -> Result<()> { pub fn dump(file: &PathBuf) -> Result<()> { let [db_container, _] = get_containers()?; - println!("dumping to local file {}", file.to_string_lossy()); + eprintln!("dumping to local file {}", file.to_string_lossy()); let file = File::create(file)?; let stdout = Stdio::from(file);