diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 17 |
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 @@ | |||
1 | use std::{fmt::Display, time::Duration}; | 1 | use std::{fmt::Display, time::Duration}; |
2 | 2 | ||
3 | use clap::{Parser, Subcommand}; | 3 | use clap::{Parser, Command, CommandFactory, Subcommand}; |
4 | use clap_complete::{generate, Shell, Generator}; | ||
4 | use config::SETTINGS; | 5 | use config::SETTINGS; |
5 | use error::CliError; | 6 | use error::CliError; |
6 | use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; | 7 | use 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 | ||
99 | fn print_completions<G: Generator>(gen: G, cmd: &mut Command) { | ||
100 | generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); | ||
101 | } | ||
102 | |||
90 | fn default_headers() -> Result<HeaderMap, CliError> { | 103 | fn 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()); |