diff options
author | fx <[email protected]> | 2023-10-18 15:11:44 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-10-18 15:11:44 +0200 |
commit | b4f59c226c6916a3e45f1a52dc6a9b15c800297a (patch) | |
tree | 07016e2ac7278da6b63aa839065c5ad572215e50 /src/main.rs | |
download | webol-cli-b4f59c226c6916a3e45f1a52dc6a9b15c800297a.tar webol-cli-b4f59c226c6916a3e45f1a52dc6a9b15c800297a.tar.gz webol-cli-b4f59c226c6916a3e45f1a52dc6a9b15c800297a.zip |
basic cli, only start and get device
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 60 |
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 @@ | |||
1 | use clap::{Parser, Subcommand}; | ||
2 | use config::SETTINGS; | ||
3 | use error::CliError; | ||
4 | use requests::{start::start, get::get}; | ||
5 | use reqwest::header::{HeaderMap, HeaderValue}; | ||
6 | |||
7 | mod config; | ||
8 | mod error; | ||
9 | mod requests; | ||
10 | |||
11 | /// webol http client | ||
12 | #[derive(Parser)] | ||
13 | #[command(author, version, about, long_about = None)] | ||
14 | struct Args { | ||
15 | #[command(subcommand)] | ||
16 | commands: Commands, | ||
17 | } | ||
18 | |||
19 | #[derive(Subcommand)] | ||
20 | enum Commands { | ||
21 | Start { | ||
22 | /// id of the device | ||
23 | id: String | ||
24 | }, | ||
25 | Get { | ||
26 | id: String | ||
27 | } | ||
28 | } | ||
29 | |||
30 | fn 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 | |||
45 | fn 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 | } | ||