diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 15dc00a..0e96624 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -5,5 +5,5 @@ mod postgres; pub use ahab::{Ahab, Commands, reject_unsupported_dry_run}; pub use django::Django; -pub use link::{Link, Store}; +pub use link::Link; pub use postgres::{Format, Postgres}; diff --git a/src/command_builder.rs b/src/command_builder.rs index 96fe2c4..245a6c2 100644 --- a/src/command_builder.rs +++ b/src/command_builder.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result, bail}; use std::{ fmt::Display, os::unix::process::CommandExt, - process::{Child, Command, ExitStatus, Stdio}, + process::{Command, ExitStatus, Stdio}, sync::OnceLock, }; @@ -97,10 +97,6 @@ impl CommandBuilder { Err(error).with_context(|| format!("running `{shown}`")) } - pub fn spawn(self) -> Result { - Ok(self.build()?.spawn()?) - } - pub fn exec_redirect_stdout(self, stdio: Stdio) -> Result<()> { if options().dry_run { eprintln!("would run `{self}`"); diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 041d969..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::{ - fs::{File, OpenOptions}, - path::PathBuf, -}; - -pub mod cli; -pub mod command_builder; -pub mod compose; -pub mod scripts; - -// NOTE: stolen from https://docs.rs/debug_print/latest/debug_print/ -#[macro_export] -macro_rules! debug_eprintln { - ($($arg:tt)*) => (#[cfg(debug_assertions)] eprintln!($($arg)*)); -} - -fn safe_create_file(path: PathBuf) -> Result { - OpenOptions::new().write(true).create_new(true).open(path) -} - -// truncate(false) keeps an existing file's contents, which is what callers creating -// an empty __init__.py want -fn create_file(path: PathBuf) -> Result { - OpenOptions::new() - .write(true) - .create(true) - .truncate(false) - .open(path) -} diff --git a/src/main.rs b/src/main.rs index e4945d3..26344b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ use std::process::ExitCode; -use ahab::{cli, command_builder, scripts}; +mod cli; +mod command_builder; +mod compose; +mod scripts; use anyhow::Result; use clap::Parser; diff --git a/src/scripts/django.rs b/src/scripts/django.rs index c302043..dc01d71 100644 --- a/src/scripts/django.rs +++ b/src/scripts/django.rs @@ -1,4 +1,4 @@ -use std::fs::create_dir; +use std::fs::{File, OpenOptions, create_dir}; use std::io::Write; use std::path::{Path, PathBuf}; @@ -6,7 +6,6 @@ use anyhow::{Result, anyhow}; use crate::compose::Compose; use crate::scripts::docker_compose; -use crate::{create_file, safe_create_file}; const DEBUG_TEMPLATE: &str = r#"from django.core.management.base import BaseCommand @@ -89,3 +88,17 @@ pub fn shell() -> Result<()> { pub fn test() -> Result<()> { manage(&["test".to_string()]) } + +fn safe_create_file(path: PathBuf) -> Result { + OpenOptions::new().write(true).create_new(true).open(path) +} + +// truncate(false) keeps an existing file's contents, which is what callers creating +// an empty __init__.py want +fn create_file(path: PathBuf) -> Result { + OpenOptions::new() + .write(true) + .create(true) + .truncate(false) + .open(path) +} diff --git a/src/scripts/docker_compose.rs b/src/scripts/docker_compose.rs index c80a1d8..73d84f2 100644 --- a/src/scripts/docker_compose.rs +++ b/src/scripts/docker_compose.rs @@ -2,14 +2,6 @@ use anyhow::Result; use crate::command_builder::CommandBuilder; -pub fn build() -> Result<()> { - CommandBuilder::docker_compose().args("build").exec() -} - -pub fn down() -> Result<()> { - CommandBuilder::docker_compose().args("down").exec() -} - pub fn run(service: &str, rest: &[String]) -> Result<()> { CommandBuilder::docker_compose() .args("run --rm") @@ -18,18 +10,6 @@ pub fn run(service: &str, rest: &[String]) -> Result<()> { .exec_replace() } -pub fn exec(service: &str, rest: &[String]) -> Result<()> { - CommandBuilder::docker_compose() - .args("exec") - .arg(service) - .args(rest) - .exec() -} - -pub fn ps() -> Result<()> { - CommandBuilder::docker_compose().args("ps").exec() -} - pub fn start(service: Option<&str>) -> Result<()> { let mut command = CommandBuilder::docker_compose().args("start"); if let Some(service) = service { @@ -46,14 +26,3 @@ pub fn stop() -> Result<()> { pub fn up() -> Result<()> { CommandBuilder::docker_compose().args("up -d").exec() } - -pub fn rebuild() -> Result<()> { - stop()?; - build()?; - up() -} - -pub fn restart() -> Result<()> { - stop()?; - up() -}