summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 15 insertions, 2 deletions
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 @@
1use std::{fmt::Display, time::Duration}; 1use std::{fmt::Display, time::Duration};
2 2
3use clap::{Parser, Subcommand}; 3use clap::{Parser, Command, CommandFactory, Subcommand};
4use clap_complete::{generate, Shell, Generator};
4use config::SETTINGS; 5use config::SETTINGS;
5use error::CliError; 6use error::CliError;
6use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; 7use indicatif::{ProgressBar, ProgressStyle, MultiProgress};
@@ -39,7 +40,10 @@ enum Commands {
39 Device { 40 Device {
40 #[command(subcommand)] 41 #[command(subcommand)]
41 devicecmd: DeviceCmd, 42 devicecmd: DeviceCmd,
42 } 43 },
44 CliGen {
45 id: Shell,
46 },
43} 47}
44 48
45#[derive(Subcommand)] 49#[derive(Subcommand)]
@@ -81,12 +85,21 @@ async fn main() -> Result<(), CliError> {
81 device::post(id, mac, broadcast_addr, ip).await?; 85 device::post(id, mac, broadcast_addr, ip).await?;
82 }, 86 },
83 } 87 }
88 },
89 Commands::CliGen { id } => {
90 eprintln!("Generating completion file for {id:?}...");
91 let mut cmd = Args::command();
92 print_completions(id, &mut cmd)
84 } 93 }
85 } 94 }
86 95
87 Ok(()) 96 Ok(())
88} 97}
89 98
99fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
100 generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout());
101}
102
90fn default_headers() -> Result<HeaderMap, CliError> { 103fn default_headers() -> Result<HeaderMap, CliError> {
91 let mut map = HeaderMap::new(); 104 let mut map = HeaderMap::new();
92 map.append("Accept-Content", HeaderValue::from_str("application/json").unwrap()); 105 map.append("Accept-Content", HeaderValue::from_str("application/json").unwrap());