feat: compile time completion generation
Removed `completion` command in favor of compile time completion generation. This tool will only be build from source for the foreseeable future so this makes sense for now.
This commit is contained in:
parent
e061d6dc6c
commit
2754a3bb30
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||
license = "MIT"
|
||||
authors = ["Matej Janežič <janezic.mj@gmail.com>"]
|
||||
repository = "https://github.com/janezicmatej/ahab.git"
|
||||
build = "build.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@ -15,3 +16,7 @@ clap = { version = "4.3.0", features = ["derive"] }
|
|||
clap_complete = "4.3.0"
|
||||
anyhow = "1.0.71"
|
||||
dotenvy = "0.15.7"
|
||||
|
||||
[build-dependencies]
|
||||
clap = { version = "4.3.0", features = ["derive"] }
|
||||
clap_complete = "4.3.0"
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
use clap::{CommandFactory, ValueEnum};
|
||||
use clap_complete::{generate_to, Shell};
|
||||
use std::{env, io::Error};
|
||||
|
||||
include!("src/cli/mod.rs");
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let outdir = match env::var_os("OUT_DIR") {
|
||||
None => return Ok(()),
|
||||
Some(outdir) => outdir,
|
||||
};
|
||||
|
||||
let mut cmd = ahab::Ahab::command();
|
||||
|
||||
for shell in Shell::value_variants() {
|
||||
let path = generate_to(*shell, &mut cmd, "ahab", &outdir)?;
|
||||
|
||||
println!("cargo:warning=completion file is generated: {path:?}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
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)]
|
||||
|
@ -12,12 +11,6 @@ pub struct Ahab {
|
|||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Commands {
|
||||
/// Generate completion files
|
||||
Completion {
|
||||
#[arg(value_enum)]
|
||||
shell: Shell,
|
||||
},
|
||||
|
||||
/// Docker related subcommands
|
||||
Docker {
|
||||
#[command(subcommand)]
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -1,7 +1,7 @@
|
|||
use ahab::{cli, scripts};
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{CommandFactory, Parser};
|
||||
use clap::Parser;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// always load dotenv on start
|
||||
|
@ -13,15 +13,6 @@ 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::Docker { command } => match command {
|
||||
cli::Docker::StopAll => scripts::docker::stop_all(),
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue