feat: swap println for eprintln
This commit is contained in:
parent
6fcf48ed61
commit
e6c0c1495a
|
@ -9,7 +9,7 @@ use std::{
|
|||
process::{Child, Command, Stdio},
|
||||
};
|
||||
|
||||
use crate::debug_println;
|
||||
use crate::debug_eprintln;
|
||||
|
||||
pub struct Args(Vec<String>);
|
||||
|
||||
|
@ -64,7 +64,7 @@ impl CommandBuilder {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Result<Command> {
|
||||
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);
|
||||
|
|
|
@ -14,6 +14,10 @@ pub mod scripts;
|
|||
macro_rules! debug_println {
|
||||
($($arg:tt)*) => (if ::std::cfg!(debug_assertions) { ::std::println!($($arg)*); })
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! debug_eprintln {
|
||||
($($arg:tt)*) => (#[cfg(debug_assertions)] eprintln!($($arg)*));
|
||||
}
|
||||
|
||||
fn safe_create_file(path: PathBuf) -> Result<File, std::io::Error> {
|
||||
OpenOptions::new().write(true).create_new(true).open(path)
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::{create_file, safe_create_file};
|
|||
|
||||
fn get_django_settings_module() -> Result<String> {
|
||||
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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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"),
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue