use clap::{Parser, Subcommand};
use dsd_util::commands::{init, logs, nuke, restart, stats, update};
const DEFAULT_ARG_PROJECT_DIR: &str = "/var/lib/docker-stack-deploy";
const DEFAULT_ARG_TAIL: &str = "100";
#[derive(Debug, Parser)]
#[command(version, about = "A simple helper for managing your docker-stack-deploy containers.", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
Init {
#[arg(short, long, default_value = DEFAULT_ARG_PROJECT_DIR)]
project_dir: String,
git_url: String,
},
Logs {
containers: Option<Vec<String>>,
#[arg(short, long)]
stacks: Option<Vec<String>>,
#[arg(short, long, default_value = DEFAULT_ARG_TAIL)]
tail: u32,
#[arg(short, long)]
all: bool,
},
Nuke,
Restart {
containers: Option<Vec<String>>,
#[arg(short, long)]
stacks: Option<Vec<String>>,
#[arg(short, long)]
all: bool,
},
Stats {
containers: Option<Vec<String>>,
#[arg(short, long)]
stacks: Option<Vec<String>>,
#[arg(short, long)]
all: bool,
},
Update {
containers: Option<Vec<String>>,
#[arg(short, long)]
stacks: Option<Vec<String>>,
#[arg(short, long)]
all: bool,
},
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Init {
project_dir,
git_url,
} => init(project_dir, git_url)?,
Commands::Logs {
containers,
stacks,
tail,
all,
} => logs(containers, stacks, tail, all)?,
Commands::Nuke => nuke()?,
Commands::Restart {
containers,
stacks,
all,
} => restart(containers, stacks, all)?,
Commands::Stats {
containers,
stacks,
all,
} => stats(containers, stacks, all)?,
Commands::Update {
containers,
stacks,
all,
} => update(containers, stacks, all)?,
}
Ok(())
}