79 lines
1.9 KiB
Rust
79 lines
1.9 KiB
Rust
use super::{Django, Link, Postgres, Store};
|
|
use clap::builder::styling::{AnsiColor, Effects, Styles};
|
|
|
|
use clap::{Parser, Subcommand};
|
|
use clap_complete::Shell;
|
|
|
|
/// A program for interacting with various dockerized applications
|
|
#[derive(Parser, Debug)]
|
|
#[command(version, about, long_about = None)]
|
|
#[command(styles = help_styles())]
|
|
pub struct Ahab {
|
|
#[command(subcommand)]
|
|
pub command: Commands,
|
|
|
|
/// Print each docker command as it runs
|
|
#[arg(short, long, global = true)]
|
|
pub verbose: bool,
|
|
|
|
/// Print only what was asked for, not the progress along the way
|
|
#[arg(short, long, global = true, conflicts_with = "verbose")]
|
|
pub quiet: bool,
|
|
|
|
/// Print the docker commands that would run, without running them
|
|
#[arg(long, global = true)]
|
|
pub dry_run: bool,
|
|
}
|
|
#[derive(Debug, Subcommand)]
|
|
pub enum Commands {
|
|
/// Django related subcommands
|
|
Django {
|
|
#[command(subcommand)]
|
|
command: Django,
|
|
},
|
|
|
|
/// Postgres related subcommands
|
|
Postgres {
|
|
#[command(subcommand)]
|
|
command: Postgres,
|
|
},
|
|
|
|
/// Out-of-repo store related subcommands
|
|
Link {
|
|
#[command(subcommand)]
|
|
command: Link,
|
|
},
|
|
|
|
/// Show what ahab makes of this project
|
|
Status {
|
|
#[command(flatten)]
|
|
store: Store,
|
|
},
|
|
|
|
/// Print a shell completion script on stdout
|
|
Completions {
|
|
/// Shell to generate the script for
|
|
shell: Shell,
|
|
},
|
|
}
|
|
|
|
// clap styles headers bold by default but adds no colour
|
|
fn help_styles() -> Styles {
|
|
Styles::styled()
|
|
.header(AnsiColor::Green.on_default() | Effects::BOLD)
|
|
.usage(AnsiColor::Green.on_default() | Effects::BOLD)
|
|
.literal(AnsiColor::Cyan.on_default() | Effects::BOLD)
|
|
.placeholder(AnsiColor::Cyan.on_default())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::Ahab;
|
|
use clap::CommandFactory;
|
|
|
|
#[test]
|
|
fn the_command_is_well_formed() {
|
|
Ahab::command().debug_assert();
|
|
}
|
|
}
|