add compose down and structure project better

This commit is contained in:
2024-08-27 00:18:33 +02:00
parent eb145cdf31
commit d22037031a
18 changed files with 521 additions and 330 deletions

16
cli/Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "bollard_compose_cli"
version = "0.1.0"
edition = "2021"
[dependencies]
bollard_compose = { path = "../lib" }
clap = { version = "4.5.16", features = ["derive"] }
log.workspace = true
tokio.workspace = true
anyhow.workspace = true
[[bin]]
name = "bollard_compose_cli"
path = "src/main.rs"

39
cli/src/main.rs Normal file
View File

@ -0,0 +1,39 @@
use bollard_compose::{down, ps, up};
use clap::{arg, Command};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let matches = Command::new("bollard_compose_cli")
.version(env!("CARGO_PKG_VERSION"))
.author("Your Name <your.email@example.com>")
.about("A CLI for managing Docker Compose in Rust")
.subcommand_required(true)
.arg_required_else_help(true)
.arg(arg!(-f --file <FILE> "Sets a custom Docker Compose file"))
.subcommand(
Command::new("up")
.about("Start the services defined in the Docker Compose file")
.arg(arg!(-d --detach "Run in the background")),
)
.subcommand(Command::new("down").about("Stop and remove the services"))
.subcommand(Command::new("ps").about("List containers"))
.get_matches();
match matches.subcommand() {
Some(("up", sub_matches)) => {
let detach = sub_matches.get_one::<bool>("detach").unwrap_or(&false);
let file = matches.get_one::<String>("file").cloned();
up(file, *detach).await?;
}
Some(("down", _)) => {
let file = matches.get_one::<String>("file").cloned();
down(file).await?;
}
Some(("ps", _)) => {
ps().await?;
}
_ => unreachable!(),
}
Ok(())
}