feat: prepare initial cli layout
Made initial command scopes d -> docker related commands dc -> docker compose related commands dj -> django related commands pg -> postgres related commands
This commit is contained in:
parent
f6e9c7953a
commit
eb232a93f8
|
@ -0,0 +1,37 @@
|
||||||
|
use super::{Django, Docker, DockerCompose, Postgres};
|
||||||
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
|
/// A program for interacting with various dockerized applications.
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(author, version, about, long_about=None)]
|
||||||
|
pub struct Ahab {
|
||||||
|
#[command(subcommand)]
|
||||||
|
pub command: Commands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Subcommand)]
|
||||||
|
pub enum Commands {
|
||||||
|
/// Docker related subcommands
|
||||||
|
D {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Docker,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Docker compose related subcommands
|
||||||
|
Dc {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: DockerCompose,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Docker compose related subcommands
|
||||||
|
Dj {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Django,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Postgres related subcommands
|
||||||
|
Pg {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Postgres,
|
||||||
|
},
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
pub enum Django {
|
||||||
|
/// Prepare empty management command 'command' in app 'app'.
|
||||||
|
MakeCommand {
|
||||||
|
#[arg(value_enum)]
|
||||||
|
app: PathBuf,
|
||||||
|
#[arg(value_enum)]
|
||||||
|
command: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Run Django's manage.py makemigrations.
|
||||||
|
Makemigrations,
|
||||||
|
|
||||||
|
/// Pass arguments to Django's manage.py.
|
||||||
|
Manage {
|
||||||
|
#[arg(value_enum)]
|
||||||
|
rest: Vec<String>,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Run Django's manage.py migrate.
|
||||||
|
Migrate,
|
||||||
|
|
||||||
|
/// Run Django's manage.py shell.
|
||||||
|
Shell,
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
pub enum Docker {
|
||||||
|
/// Stop all containers via `docker stop $(docker ps -q)`
|
||||||
|
StopAll,
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
use clap::Subcommand;
|
||||||
|
|
||||||
|
/// Wraper for docker compose; autodiscover compose file and source .env file.
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
pub enum DockerCompose {
|
||||||
|
/// Build containers.
|
||||||
|
Build,
|
||||||
|
|
||||||
|
/// Down containers.
|
||||||
|
Down,
|
||||||
|
|
||||||
|
/// Stop, build and start containers.
|
||||||
|
Rebuild,
|
||||||
|
|
||||||
|
/// Stop and start containers.
|
||||||
|
Restart,
|
||||||
|
|
||||||
|
/// Start containers.
|
||||||
|
Start,
|
||||||
|
|
||||||
|
/// Stop containers.
|
||||||
|
Stop,
|
||||||
|
|
||||||
|
/// Up containers.
|
||||||
|
Up,
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
mod ahab;
|
||||||
|
mod django;
|
||||||
|
mod docker;
|
||||||
|
mod docker_compose;
|
||||||
|
mod postgres;
|
||||||
|
|
||||||
|
pub use ahab::{Ahab, Commands};
|
||||||
|
pub use django::Django;
|
||||||
|
pub use docker::Docker;
|
||||||
|
pub use docker_compose::DockerCompose;
|
||||||
|
pub use postgres::Postgres;
|
|
@ -0,0 +1,18 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::Subcommand;
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
pub enum Postgres {
|
||||||
|
/// Import dump via pg_restore
|
||||||
|
Import {
|
||||||
|
#[arg(value_enum)]
|
||||||
|
path: PathBuf,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Dump via pg_dump with format=c
|
||||||
|
Dump {
|
||||||
|
#[arg(value_enum)]
|
||||||
|
path: PathBuf,
|
||||||
|
},
|
||||||
|
}
|
34
src/main.rs
34
src/main.rs
|
@ -1,5 +1,39 @@
|
||||||
|
mod cli;
|
||||||
|
mod scripts;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
let args = cli::Ahab::parse();
|
||||||
|
|
||||||
|
match args.command {
|
||||||
|
cli::Commands::D { command } => match command {
|
||||||
|
cli::Docker::StopAll => scripts::docker::stop_all(),
|
||||||
|
},
|
||||||
|
cli::Commands::Dc { command } => match command {
|
||||||
|
cli::DockerCompose::Build => scripts::docker_compose::build(),
|
||||||
|
cli::DockerCompose::Down => scripts::docker_compose::down(),
|
||||||
|
cli::DockerCompose::Rebuild => scripts::docker_compose::rebuild(),
|
||||||
|
cli::DockerCompose::Restart => scripts::docker_compose::restart(),
|
||||||
|
cli::DockerCompose::Start => scripts::docker_compose::start(),
|
||||||
|
cli::DockerCompose::Stop => scripts::docker_compose::stop(),
|
||||||
|
cli::DockerCompose::Up => scripts::docker_compose::up(),
|
||||||
|
},
|
||||||
|
cli::Commands::Dj { command } => match command {
|
||||||
|
cli::Django::MakeCommand { app, command } => {
|
||||||
|
scripts::django::make_command(&app, &command)
|
||||||
|
}
|
||||||
|
cli::Django::Makemigrations => scripts::django::makemigrations(),
|
||||||
|
cli::Django::Manage { rest } => scripts::django::manage(&rest),
|
||||||
|
cli::Django::Migrate => scripts::django::migrate(),
|
||||||
|
cli::Django::Shell => scripts::django::shell(),
|
||||||
|
},
|
||||||
|
cli::Commands::Pg { command } => match command {
|
||||||
|
cli::Postgres::Import { path } => scripts::postgres::import(&path),
|
||||||
|
cli::Postgres::Dump { path } => scripts::postgres::dump(&path),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub fn make_command(app: &PathBuf, command: &str) {
|
||||||
|
println!("{app:?} and {command:?}");
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn makemigrations() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn manage(command: &[String]) {
|
||||||
|
println!("{command:?}");
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn migrate() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn shell() {
|
||||||
|
todo!()
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn stop_all() {
|
||||||
|
todo!()
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
pub fn build() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn down() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn rebuild() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn restart() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn start() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn stop() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
pub fn up() {
|
||||||
|
todo!()
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod django;
|
||||||
|
pub mod docker;
|
||||||
|
pub mod docker_compose;
|
||||||
|
pub mod postgres;
|
|
@ -0,0 +1,11 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub fn import(path: &PathBuf) {
|
||||||
|
println!("{path:?}");
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dump(path: &PathBuf) {
|
||||||
|
println!("{path:?}");
|
||||||
|
todo!()
|
||||||
|
}
|
Loading…
Reference in New Issue