summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs22
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};
3use crate::config::Config; 3use crate::config::Config;
4use clap::{Command, CommandFactory, Parser, Subcommand}; 4use clap::{Command, CommandFactory, Parser, Subcommand};
5use clap_complete::{generate, Generator, Shell}; 5use clap_complete::{generate, Generator, Shell};
6use error::CliError; 6use error::Error;
7use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 7use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
8use requests::{device, start::start}; 8use requests::{device, start::start};
9use reqwest::header::{HeaderMap, HeaderValue}; 9use reqwest::header::{HeaderMap, HeaderValue};
@@ -66,8 +66,8 @@ enum DeviceCmd {
66} 66}
67 67
68#[tokio::main] 68#[tokio::main]
69async fn main() -> Result<(), CliError> { 69async 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
113fn default_headers(config: &Config) -> Result<HeaderMap, CliError> { 113fn 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
131fn format_url(config: &Config, path: &str, protocol: Protocols) -> Result<String, CliError> { 131fn 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
135fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { 135fn 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
144fn finish_pb(pb: ProgressBar, message: String, template: &str) { 144fn 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}