From 8fab2e7c3a38a91c8f5549b639e7f2ac4ae1a420 Mon Sep 17 00:00:00 2001 From: fx Date: Sat, 21 Oct 2023 17:43:31 +0200 Subject: added device add and update --- src/main.rs | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/main.rs') 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 @@ use clap::{Parser, Subcommand}; use config::SETTINGS; use error::CliError; -use requests::{start::start, get::get}; +use requests::{start::start, device}; use reqwest::header::{HeaderMap, HeaderValue}; use serde::Deserialize; @@ -23,11 +23,29 @@ enum Commands { /// id of the device id: String }, - Get { - id: String + Device { + #[command(subcommand)] + devicecmd: DeviceCmd, } } +#[derive(Subcommand)] +enum DeviceCmd { + Add { + id: String, + mac: String, + broadcast_addr: String + }, + Get { + id: String, + }, + Edit { + id: String, + mac: String, + broadcast_addr: String + }, +} + fn main() -> Result<(), CliError> { let cli = Args::parse(); @@ -35,8 +53,18 @@ fn main() -> Result<(), CliError> { Commands::Start { id } => { start(id)?; }, - Commands::Get { id } => { - get(id)?; + Commands::Device { devicecmd } => { + match devicecmd { + DeviceCmd::Add { id, mac, broadcast_addr } => { + device::put(id, mac, broadcast_addr)?; + }, + DeviceCmd::Get { id } => { + device::get(id)?; + }, + DeviceCmd::Edit { id, mac, broadcast_addr } => { + device::post(id, mac, broadcast_addr)?; + }, + } } } @@ -57,7 +85,14 @@ fn default_headers() -> Result { ); Ok(map) +} +fn format_url(path: &str) -> Result { + Ok(format!( + "{}/{}", + SETTINGS.get_string("server").map_err(CliError::Config)?, + path + )) } #[derive(Debug, Deserialize)] -- cgit v1.2.3