summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..d2f0c3a
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,60 @@
1use clap::{Parser, Subcommand};
2use config::SETTINGS;
3use error::CliError;
4use requests::{start::start, get::get};
5use reqwest::header::{HeaderMap, HeaderValue};
6
7mod config;
8mod error;
9mod requests;
10
11/// webol http client
12#[derive(Parser)]
13#[command(author, version, about, long_about = None)]
14struct Args {
15 #[command(subcommand)]
16 commands: Commands,
17}
18
19#[derive(Subcommand)]
20enum Commands {
21 Start {
22 /// id of the device
23 id: String
24 },
25 Get {
26 id: String
27 }
28}
29
30fn main() -> Result<(), CliError> {
31 let cli = Args::parse();
32
33 match cli.commands {
34 Commands::Start { id } => {
35 start(id)?;
36 },
37 Commands::Get { id } => {
38 get(id)?;
39 }
40 }
41
42 Ok(())
43}
44
45fn default_headers() -> Result<HeaderMap, CliError> {
46 let mut map = HeaderMap::new();
47 map.append("Accept-Content", HeaderValue::from_str("application/json").unwrap());
48 map.append("Content-Type", HeaderValue::from_str("application/json").unwrap());
49 map.append(
50 "Authorization",
51 HeaderValue::from_str(
52 SETTINGS.get_string("key")
53 .map_err(CliError::Config)?
54 .as_str()
55 ).unwrap()
56 );
57
58 Ok(map)
59
60}