refactor: build one binary instead of a library and a binary

This commit is contained in:
2026-09-08 11:26:33 +00:00
parent 27c6b261a6
commit 056da8b9b2
6 changed files with 21 additions and 69 deletions

View File

@@ -5,5 +5,5 @@ mod postgres;
pub use ahab::{Ahab, Commands, reject_unsupported_dry_run}; pub use ahab::{Ahab, Commands, reject_unsupported_dry_run};
pub use django::Django; pub use django::Django;
pub use link::{Link, Store}; pub use link::Link;
pub use postgres::{Format, Postgres}; pub use postgres::{Format, Postgres};

View File

@@ -2,7 +2,7 @@ use anyhow::{Context, Result, bail};
use std::{ use std::{
fmt::Display, fmt::Display,
os::unix::process::CommandExt, os::unix::process::CommandExt,
process::{Child, Command, ExitStatus, Stdio}, process::{Command, ExitStatus, Stdio},
sync::OnceLock, sync::OnceLock,
}; };
@@ -97,10 +97,6 @@ impl CommandBuilder {
Err(error).with_context(|| format!("running `{shown}`")) Err(error).with_context(|| format!("running `{shown}`"))
} }
pub fn spawn(self) -> Result<Child> {
Ok(self.build()?.spawn()?)
}
pub fn exec_redirect_stdout(self, stdio: Stdio) -> Result<()> { pub fn exec_redirect_stdout(self, stdio: Stdio) -> Result<()> {
if options().dry_run { if options().dry_run {
eprintln!("would run `{self}`"); eprintln!("would run `{self}`");

View File

@@ -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<File, std::io::Error> {
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<File, std::io::Error> {
OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(path)
}

View File

@@ -1,6 +1,9 @@
use std::process::ExitCode; use std::process::ExitCode;
use ahab::{cli, command_builder, scripts}; mod cli;
mod command_builder;
mod compose;
mod scripts;
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Parser;

View File

@@ -1,4 +1,4 @@
use std::fs::create_dir; use std::fs::{File, OpenOptions, create_dir};
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@@ -6,7 +6,6 @@ use anyhow::{Result, anyhow};
use crate::compose::Compose; use crate::compose::Compose;
use crate::scripts::docker_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 const DEBUG_TEMPLATE: &str = r#"from django.core.management.base import BaseCommand
@@ -89,3 +88,17 @@ pub fn shell() -> Result<()> {
pub fn test() -> Result<()> { pub fn test() -> Result<()> {
manage(&["test".to_string()]) manage(&["test".to_string()])
} }
fn safe_create_file(path: PathBuf) -> Result<File, std::io::Error> {
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<File, std::io::Error> {
OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(path)
}

View File

@@ -2,14 +2,6 @@ use anyhow::Result;
use crate::command_builder::CommandBuilder; 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<()> { pub fn run(service: &str, rest: &[String]) -> Result<()> {
CommandBuilder::docker_compose() CommandBuilder::docker_compose()
.args("run --rm") .args("run --rm")
@@ -18,18 +10,6 @@ pub fn run(service: &str, rest: &[String]) -> Result<()> {
.exec_replace() .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<()> { pub fn start(service: Option<&str>) -> Result<()> {
let mut command = CommandBuilder::docker_compose().args("start"); let mut command = CommandBuilder::docker_compose().args("start");
if let Some(service) = service { if let Some(service) = service {
@@ -46,14 +26,3 @@ pub fn stop() -> Result<()> {
pub fn up() -> Result<()> { pub fn up() -> Result<()> {
CommandBuilder::docker_compose().args("up -d").exec() CommandBuilder::docker_compose().args("up -d").exec()
} }
pub fn rebuild() -> Result<()> {
stop()?;
build()?;
up()
}
pub fn restart() -> Result<()> {
stop()?;
up()
}