refactor: build one binary instead of a library and a binary
This commit is contained in:
@@ -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};
|
||||
|
||||
@@ -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<Child> {
|
||||
Ok(self.build()?.spawn()?)
|
||||
}
|
||||
|
||||
pub fn exec_redirect_stdout(self, stdio: Stdio) -> Result<()> {
|
||||
if options().dry_run {
|
||||
eprintln!("would run `{self}`");
|
||||
|
||||
29
src/lib.rs
29
src/lib.rs
@@ -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)
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user