diff options
author | fx <[email protected]> | 2023-10-21 17:43:31 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-10-21 17:43:31 +0200 |
commit | 8fab2e7c3a38a91c8f5549b639e7f2ac4ae1a420 (patch) | |
tree | 09a886de17d8dc5e36d89068828380e936b47650 /src/main.rs | |
parent | eb0a092fc53964e02a09da2d92a1f8a3042a1360 (diff) | |
download | webol-cli-8fab2e7c3a38a91c8f5549b639e7f2ac4ae1a420.tar webol-cli-8fab2e7c3a38a91c8f5549b639e7f2ac4ae1a420.tar.gz webol-cli-8fab2e7c3a38a91c8f5549b639e7f2ac4ae1a420.zip |
added device add and update
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index e6ca3ef..ab7e476 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use clap::{Parser, Subcommand}; | 1 | use clap::{Parser, Subcommand}; |
2 | use config::SETTINGS; | 2 | use config::SETTINGS; |
3 | use error::CliError; | 3 | use error::CliError; |
4 | use requests::{start::start, get::get}; | 4 | use requests::{start::start, device}; |
5 | use reqwest::header::{HeaderMap, HeaderValue}; | 5 | use reqwest::header::{HeaderMap, HeaderValue}; |
6 | use serde::Deserialize; | 6 | use serde::Deserialize; |
7 | 7 | ||
@@ -23,11 +23,29 @@ enum Commands { | |||
23 | /// id of the device | 23 | /// id of the device |
24 | id: String | 24 | id: String |
25 | }, | 25 | }, |
26 | Get { | 26 | Device { |
27 | id: String | 27 | #[command(subcommand)] |
28 | devicecmd: DeviceCmd, | ||
28 | } | 29 | } |
29 | } | 30 | } |
30 | 31 | ||
32 | #[derive(Subcommand)] | ||
33 | enum DeviceCmd { | ||
34 | Add { | ||
35 | id: String, | ||
36 | mac: String, | ||
37 | broadcast_addr: String | ||
38 | }, | ||
39 | Get { | ||
40 | id: String, | ||
41 | }, | ||
42 | Edit { | ||
43 | id: String, | ||
44 | mac: String, | ||
45 | broadcast_addr: String | ||
46 | }, | ||
47 | } | ||
48 | |||
31 | fn main() -> Result<(), CliError> { | 49 | fn main() -> Result<(), CliError> { |
32 | let cli = Args::parse(); | 50 | let cli = Args::parse(); |
33 | 51 | ||
@@ -35,8 +53,18 @@ fn main() -> Result<(), CliError> { | |||
35 | Commands::Start { id } => { | 53 | Commands::Start { id } => { |
36 | start(id)?; | 54 | start(id)?; |
37 | }, | 55 | }, |
38 | Commands::Get { id } => { | 56 | Commands::Device { devicecmd } => { |
39 | get(id)?; | 57 | match devicecmd { |
58 | DeviceCmd::Add { id, mac, broadcast_addr } => { | ||
59 | device::put(id, mac, broadcast_addr)?; | ||
60 | }, | ||
61 | DeviceCmd::Get { id } => { | ||
62 | device::get(id)?; | ||
63 | }, | ||
64 | DeviceCmd::Edit { id, mac, broadcast_addr } => { | ||
65 | device::post(id, mac, broadcast_addr)?; | ||
66 | }, | ||
67 | } | ||
40 | } | 68 | } |
41 | } | 69 | } |
42 | 70 | ||
@@ -57,7 +85,14 @@ fn default_headers() -> Result<HeaderMap, CliError> { | |||
57 | ); | 85 | ); |
58 | 86 | ||
59 | Ok(map) | 87 | Ok(map) |
88 | } | ||
60 | 89 | ||
90 | fn format_url(path: &str) -> Result<String, CliError> { | ||
91 | Ok(format!( | ||
92 | "{}/{}", | ||
93 | SETTINGS.get_string("server").map_err(CliError::Config)?, | ||
94 | path | ||
95 | )) | ||
61 | } | 96 | } |
62 | 97 | ||
63 | #[derive(Debug, Deserialize)] | 98 | #[derive(Debug, Deserialize)] |