160 lines
3.6 KiB
Rust
160 lines
3.6 KiB
Rust
use argh::FromArgs;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(description = "Tool for gathering location data from Yepzon servers.")]
|
|
pub struct EnvOpt {
|
|
#[argh(
|
|
option,
|
|
short = 'c',
|
|
description = "config.toml file path.",
|
|
default = "PathBuf::from(\"config.toml\")"
|
|
)]
|
|
pub config: PathBuf,
|
|
#[argh(subcommand)]
|
|
pub subcommand: Subcommand,
|
|
}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(subcommand)]
|
|
pub enum Subcommand {
|
|
Between(BetweenOpt),
|
|
Init(InitOpt),
|
|
Api(ApiOpt),
|
|
Nick(NickOpt),
|
|
#[cfg(debug_assertions)]
|
|
Get(GetOpt),
|
|
}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(
|
|
subcommand,
|
|
name = "between",
|
|
description = "fetch locations for a given section in time.\n<device> nickname, or index from nick list.\nsince and until in format dd.mm.yyy, OR hh:mm:ss, OR dd.mm.yyy-hh:mm:ss"
|
|
)]
|
|
pub struct BetweenOpt {
|
|
#[argh(positional, description = "device to be fetched")]
|
|
pub device: String, // Device = tag, but in human speech
|
|
#[argh(
|
|
option,
|
|
short = 's',
|
|
description = "the oldest point in time to get locations from."
|
|
)]
|
|
pub since: String,
|
|
#[argh(
|
|
option,
|
|
short = 'u',
|
|
description = "the most recent point in time to get locations from, default = now."
|
|
)]
|
|
pub until: Option<String>,
|
|
}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(subcommand, name = "init", description = "initializes a config file")]
|
|
pub struct InitOpt {
|
|
#[argh(
|
|
option,
|
|
short = 'a',
|
|
description = "the API-key for the generated config-file"
|
|
)]
|
|
pub api_key: Option<String>,
|
|
}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(
|
|
subcommand,
|
|
name = "api",
|
|
description = "check integrity of API and API-key validity"
|
|
)]
|
|
pub struct ApiOpt {}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(
|
|
subcommand,
|
|
name = "nick",
|
|
description = "provides nicknaming to devices"
|
|
)]
|
|
pub struct NickOpt {
|
|
#[argh(subcommand)]
|
|
pub subcommand: NickSub,
|
|
}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(subcommand)]
|
|
pub enum NickSub {
|
|
List(NickListOpt),
|
|
Set(NickSetOpt),
|
|
}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(
|
|
subcommand,
|
|
name = "list",
|
|
description = "List all devices and their current nicknames"
|
|
)]
|
|
pub struct NickListOpt {}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(
|
|
subcommand,
|
|
name = "set",
|
|
description = "Set nickname for given device. Give device index from nick list, or current nickname."
|
|
)]
|
|
pub struct NickSetOpt {
|
|
#[argh(positional, description = "the device index or nickname")]
|
|
pub device: String,
|
|
#[argh(positional, description = "the new nickname for the device")]
|
|
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 {
|
|
Tags(GetTagsOpt),
|
|
States(GetStatesOpt),
|
|
Locations(GetLocationsOpt),
|
|
}
|
|
|
|
#[derive(FromArgs)]
|
|
#[argh(
|
|
subcommand,
|
|
name = "tags",
|
|
description = "Get all tags connected to this API-key"
|
|
)]
|
|
pub struct GetTagsOpt {}
|
|
|
|
#[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: Option<String>,
|
|
}
|