From 93de8742961287cb9cfd08e68c8afa2347585a73 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 13 Nov 2023 15:21:25 +0100 Subject: add completion and cargo update --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 204e671..afe6fac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::{fmt::Display, time::Duration}; -use clap::{Parser, Subcommand}; +use clap::{Parser, Command, CommandFactory, Subcommand}; +use clap_complete::{generate, Shell, Generator}; use config::SETTINGS; use error::CliError; use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; @@ -39,7 +40,10 @@ enum Commands { Device { #[command(subcommand)] devicecmd: DeviceCmd, - } + }, + CliGen { + id: Shell, + }, } #[derive(Subcommand)] @@ -81,12 +85,21 @@ async fn main() -> Result<(), CliError> { device::post(id, mac, broadcast_addr, ip).await?; }, } + }, + Commands::CliGen { id } => { + eprintln!("Generating completion file for {id:?}..."); + let mut cmd = Args::command(); + print_completions(id, &mut cmd) } } Ok(()) } +fn print_completions(gen: G, cmd: &mut Command) { + generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); +} + fn default_headers() -> Result { let mut map = HeaderMap::new(); map.append("Accept-Content", HeaderValue::from_str("application/json").unwrap()); -- cgit v1.2.3