yepzon-locationer/src/cmd/args.rs

186 lines
4.2 KiB
Rust

use argh::FromArgs;
use std::path::PathBuf;
#[derive(FromArgs)]
#[argh(
description = "Tool for gathering location data from Yepzon servers. Run without subcommands on windows to open nwg UI."
)]
pub struct EnvOpt {
#[argh(
option,
short = 'c',
description = "config.toml file path.",
default = "PathBuf::from(\"config.toml\")"
)]
pub config: PathBuf,
#[argh(subcommand)]
pub subcommand: Option<Subcommand>,
}
#[derive(FromArgs)]
#[argh(subcommand)]
pub enum Subcommand {
Between(BetweenOpt),
Init(InitOpt),
Api(ApiOpt),
ShareToken(ShareTokenOpt),
Nick(NickOpt),
#[cfg(debug_assertions)]
Get(GetOpt),
}
#[derive(FromArgs)]
#[argh(
subcommand,
name = "between",
description = "fetch locations for a given section in time. <device> nickname, or index from nick list. since 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 = "sharetoken",
description = "retrieve share token for given device."
)]
pub struct ShareTokenOpt {
#[argh(positional, description = "the device index or nickname")]
pub device: String,
}
#[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 {
Tag(GetTagOpt),
Tags(GetTagsOpt),
States(GetStatesOpt),
Locations(GetLocationsOpt),
}
#[derive(FromArgs)]
#[argh(
subcommand,
name = "tag",
description = "Get a specific tag connected to this API-key"
)]
pub struct GetTagOpt {
#[argh(positional, description = "the device in question")]
pub device: String,
}
#[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>,
}