feat: add clap_complete for generating completion files
`ahab generate <shell>` can now be used to generte completion files for this tool.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use super::{Django, Docker, DockerCompose, Postgres};
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap_complete::Shell;
|
||||
|
||||
/// A program for interacting with various dockerized applications.
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -11,6 +12,12 @@ pub struct Ahab {
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Commands {
|
||||
/// Generate completion files
|
||||
Completion {
|
||||
#[arg(value_enum)]
|
||||
shell: Shell,
|
||||
},
|
||||
|
||||
/// Docker related subcommands
|
||||
D {
|
||||
#[command(subcommand)]
|
||||
|
11
src/main.rs
11
src/main.rs
@@ -1,7 +1,7 @@
|
||||
use ahab::{cli, scripts};
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use clap::{CommandFactory, Parser};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// always load dotenv on start
|
||||
@@ -13,6 +13,15 @@ fn main() -> Result<()> {
|
||||
let args = cli::Ahab::parse();
|
||||
|
||||
match args.command {
|
||||
cli::Commands::Completion { shell } => {
|
||||
clap_complete::generate(
|
||||
shell,
|
||||
&mut cli::Ahab::command(),
|
||||
"ahab",
|
||||
&mut std::io::stdout(),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
cli::Commands::D { command } => match command {
|
||||
cli::Docker::StopAll => scripts::docker::stop_all(),
|
||||
},
|
||||
|
Reference in New Issue
Block a user