Add get debug command
This commit is contained in:
parent
b5c93017a4
commit
23cf2c370d
13
src/api.rs
13
src/api.rs
@ -87,10 +87,10 @@ impl Display for TagModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct StateModel {
|
pub struct StateModel {
|
||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
pub timestamp: Option<String>,
|
pub timestamp: Option<String>,
|
||||||
#[serde(skip_deserializing)]
|
|
||||||
pub state: Option<String>,
|
pub state: Option<String>,
|
||||||
#[serde(rename(deserialize = "realState"))]
|
#[serde(rename(deserialize = "realState"))]
|
||||||
pub real_state: Option<String>,
|
pub real_state: Option<String>,
|
||||||
@ -150,6 +150,17 @@ impl API {
|
|||||||
Ok(response.json()?)
|
Ok(response.json()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_locations(
|
||||||
|
&mut self,
|
||||||
|
tag_id: &String,
|
||||||
|
state_id: &String,
|
||||||
|
) -> Result<Vec<LocationModel>, GenericError> {
|
||||||
|
let url = str::replace(&self.config.locations_url, "{tag}", &tag_id);
|
||||||
|
let url = str::replace(&url, "{state}", &state_id);
|
||||||
|
let response = self.request(url)?;
|
||||||
|
Ok(response.json()?)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn queue_location(&mut self, tag_id: &String, state_id: &String) {
|
pub fn queue_location(&mut self, tag_id: &String, state_id: &String) {
|
||||||
let url = str::replace(&self.config.locations_url, "{tag}", &tag_id);
|
let url = str::replace(&self.config.locations_url, "{tag}", &tag_id);
|
||||||
let url = str::replace(&url, "{state}", &state_id);
|
let url = str::replace(&url, "{state}", &state_id);
|
||||||
|
43
src/cmd.rs
43
src/cmd.rs
@ -21,6 +21,7 @@ pub enum Subcommand {
|
|||||||
Between(BetweenOpt),
|
Between(BetweenOpt),
|
||||||
Init(InitOpt),
|
Init(InitOpt),
|
||||||
Nick(NickOpt),
|
Nick(NickOpt),
|
||||||
|
Get(GetOpt),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
@ -95,3 +96,45 @@ pub struct NickSetOpt {
|
|||||||
#[argh(positional, description = "the new nickname for the device")]
|
#[argh(positional, description = "the new nickname for the device")]
|
||||||
pub nickname: String,
|
pub nickname: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argh(
|
||||||
|
subcommand,
|
||||||
|
name = "get",
|
||||||
|
description = "provides nicknaming to devices"
|
||||||
|
)]
|
||||||
|
pub struct GetOpt {
|
||||||
|
#[argh(subcommand)]
|
||||||
|
pub subcommand: GetSub,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argh(subcommand)]
|
||||||
|
pub enum GetSub {
|
||||||
|
States(GetStatesOpt),
|
||||||
|
Locations(GetLocationsOpt),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argh(
|
||||||
|
subcommand,
|
||||||
|
name = "states",
|
||||||
|
description = "Get states for the given device"
|
||||||
|
)]
|
||||||
|
pub struct GetStatesOpt {
|
||||||
|
#[argh(positional, description = "the device in question")]
|
||||||
|
pub device: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argh(
|
||||||
|
subcommand,
|
||||||
|
name = "locations",
|
||||||
|
description = "Get locations for a state for the given device"
|
||||||
|
)]
|
||||||
|
pub struct GetLocationsOpt {
|
||||||
|
#[argh(positional, description = "the device in question")]
|
||||||
|
pub device: String,
|
||||||
|
#[argh(positional, description = "the state id")]
|
||||||
|
pub state: String,
|
||||||
|
}
|
||||||
|
18
src/main.rs
18
src/main.rs
@ -95,6 +95,22 @@ fn from_env(env: EnvOpt) -> Result<(), GenericError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Subcommand::Get(opt) => {
|
||||||
|
let config = Config::from_path(&env.config)?;
|
||||||
|
let mut api = API::new(config.clone());
|
||||||
|
let tags = api.get_tags()?;
|
||||||
|
match opt.subcommand {
|
||||||
|
GetSub::States(opt) => {
|
||||||
|
let tag = find_tag(opt.device, &tags, &config)?;
|
||||||
|
dbg!(api.get_states(&tag.get_id()?));
|
||||||
|
}
|
||||||
|
GetSub::Locations(opt) => {
|
||||||
|
let tag = find_tag(opt.device, &tags, &config)?;
|
||||||
|
dbg!(api.get_locations(&tag.get_id()?, &opt.state));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +168,7 @@ fn run(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{:<100}", "Done!");
|
println!("{:<100}", "\nDone!");
|
||||||
locations.sort_by(|loc1, loc2| loc2.timestamp.cmp(&loc1.timestamp));
|
locations.sort_by(|loc1, loc2| loc2.timestamp.cmp(&loc1.timestamp));
|
||||||
|
|
||||||
let locs = API::get_between(&locations, from, to, false, &config);
|
let locs = API::get_between(&locations, from, to, false, &config);
|
||||||
|
Loading…
Reference in New Issue
Block a user