diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index 0393183..cdca6cb 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -3,7 +3,7 @@ use std::{fmt::Display, time::Duration}; | |||
3 | use crate::config::Config; | 3 | use crate::config::Config; |
4 | use clap::{Command, CommandFactory, Parser, Subcommand}; | 4 | use clap::{Command, CommandFactory, Parser, Subcommand}; |
5 | use clap_complete::{generate, Generator, Shell}; | 5 | use clap_complete::{generate, Generator, Shell}; |
6 | use error::CliError; | 6 | use error::Error; |
7 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | 7 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; |
8 | use requests::{device, start::start}; | 8 | use requests::{device, start::start}; |
9 | use reqwest::header::{HeaderMap, HeaderValue}; | 9 | use reqwest::header::{HeaderMap, HeaderValue}; |
@@ -66,8 +66,8 @@ enum DeviceCmd { | |||
66 | } | 66 | } |
67 | 67 | ||
68 | #[tokio::main] | 68 | #[tokio::main] |
69 | async fn main() -> Result<(), CliError> { | 69 | async fn main() -> Result<(), Error> { |
70 | let config = Config::load().map_err(CliError::Config)?; | 70 | let config = Config::load()?; |
71 | 71 | ||
72 | let cli = Args::parse(); | 72 | let cli = Args::parse(); |
73 | 73 | ||
@@ -99,7 +99,7 @@ async fn main() -> Result<(), CliError> { | |||
99 | Commands::CliGen { id } => { | 99 | Commands::CliGen { id } => { |
100 | eprintln!("Generating completion file for {id:?}..."); | 100 | eprintln!("Generating completion file for {id:?}..."); |
101 | let mut cmd = Args::command(); | 101 | let mut cmd = Args::command(); |
102 | print_completions(id, &mut cmd) | 102 | print_completions(id, &mut cmd); |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
@@ -110,26 +110,26 @@ fn print_completions<G: Generator>(gen: G, cmd: &mut Command) { | |||
110 | generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); | 110 | generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); |
111 | } | 111 | } |
112 | 112 | ||
113 | fn default_headers(config: &Config) -> Result<HeaderMap, CliError> { | 113 | fn default_headers(config: &Config) -> Result<HeaderMap, Error> { |
114 | let mut map = HeaderMap::new(); | 114 | let mut map = HeaderMap::new(); |
115 | map.append( | 115 | map.append( |
116 | "Accept-Content", | 116 | "Accept-Content", |
117 | HeaderValue::from_str("application/json").unwrap(), | 117 | HeaderValue::from_str("application/json")? |
118 | ); | 118 | ); |
119 | map.append( | 119 | map.append( |
120 | "Content-Type", | 120 | "Content-Type", |
121 | HeaderValue::from_str("application/json").unwrap(), | 121 | HeaderValue::from_str("application/json")? |
122 | ); | 122 | ); |
123 | map.append( | 123 | map.append( |
124 | "Authorization", | 124 | "Authorization", |
125 | HeaderValue::from_str(&config.apikey).unwrap(), | 125 | HeaderValue::from_str(&config.apikey)? |
126 | ); | 126 | ); |
127 | 127 | ||
128 | Ok(map) | 128 | Ok(map) |
129 | } | 129 | } |
130 | 130 | ||
131 | fn format_url(config: &Config, path: &str, protocol: Protocols) -> Result<String, CliError> { | 131 | fn format_url(config: &Config, path: &str, protocol: &Protocols) -> String { |
132 | Ok(format!("{}://{}/{}", protocol, config.server, path)) | 132 | format!("{}://{}/{}", protocol, config.server, path) |
133 | } | 133 | } |
134 | 134 | ||
135 | fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { | 135 | fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { |
@@ -141,7 +141,7 @@ fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { | |||
141 | pb | 141 | pb |
142 | } | 142 | } |
143 | 143 | ||
144 | fn finish_pb(pb: ProgressBar, message: String, template: &str) { | 144 | fn finish_pb(pb: &ProgressBar, message: String, template: &str) { |
145 | pb.set_style(ProgressStyle::with_template(template).unwrap()); | 145 | pb.set_style(ProgressStyle::with_template(template).unwrap()); |
146 | pb.finish_with_message(message); | 146 | pb.finish_with_message(message); |
147 | } | 147 | } |