yepzon-locationer/src/cmd/args.rs

186 lines
4.2 KiB
Rust
Raw Normal View History

2020-08-23 01:18:31 +02:00
use argh::FromArgs;
2020-08-24 01:51:59 +02:00
use std::path::PathBuf;
2020-08-23 01:18:31 +02:00
#[derive(FromArgs)]
2020-08-29 02:03:28 +02:00
#[argh(
description = "Tool for gathering location data from Yepzon servers. Run without subcommands on windows to open nwg UI."
)]
2020-08-23 01:18:31 +02:00
pub struct EnvOpt {
2020-08-24 18:50:29 +02:00
#[argh(
option,
short = 'c',
description = "config.toml file path.",
default = "PathBuf::from(\"config.toml\")"
)]
pub config: PathBuf,
2020-08-23 01:18:31 +02:00
#[argh(subcommand)]
2020-08-29 01:58:17 +02:00
pub subcommand: Option<Subcommand>,
2020-08-23 01:18:31 +02:00
}
#[derive(FromArgs)]
#[argh(subcommand)]
pub enum Subcommand {
2020-08-24 18:50:29 +02:00
Between(BetweenOpt),
2020-08-23 01:18:31 +02:00
Init(InitOpt),
Api(ApiOpt),
2020-08-25 21:18:59 +02:00
ShareToken(ShareTokenOpt),
2020-08-24 18:50:29 +02:00
Nick(NickOpt),
2020-08-25 20:59:49 +02:00
#[cfg(debug_assertions)]
2020-08-24 23:14:18 +02:00
Get(GetOpt),
2020-08-23 01:18:31 +02:00
}
#[derive(FromArgs)]
2020-08-24 02:33:40 +02:00
#[argh(
subcommand,
2020-08-24 18:50:29 +02:00
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"
2020-08-24 02:33:40 +02:00
)]
2020-08-24 18:50:29 +02:00
pub struct BetweenOpt {
2020-08-24 19:05:34 +02:00
#[argh(positional, description = "device to be fetched")]
pub device: String, // Device = tag, but in human speech
2020-08-24 01:51:59 +02:00
#[argh(
option,
2020-08-24 02:33:40 +02:00
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>,
2020-08-24 01:51:59 +02:00
}
2020-08-23 01:18:31 +02:00
#[derive(FromArgs)]
2020-08-24 02:33:40 +02:00
#[argh(subcommand, name = "init", description = "initializes a config file")]
2020-08-24 19:47:11 +02:00
pub struct InitOpt {
#[argh(
option,
short = 'a',
description = "the API-key for the generated config-file"
)]
pub api_key: Option<String>,
}
2020-08-24 18:50:29 +02:00
#[derive(FromArgs)]
#[argh(
subcommand,
name = "api",
description = "check integrity of API and API-key validity"
)]
pub struct ApiOpt {}
2020-08-25 21:18:59 +02:00
#[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,
}
2020-08-24 18:50:29 +02:00
#[derive(FromArgs)]
2020-08-24 19:05:34 +02:00
#[argh(
subcommand,
name = "nick",
description = "provides nicknaming to devices"
)]
2020-08-24 18:50:29 +02:00
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",
2020-08-24 19:05:34 +02:00
description = "List all devices and their current nicknames"
2020-08-24 18:50:29 +02:00
)]
pub struct NickListOpt {}
#[derive(FromArgs)]
#[argh(
subcommand,
name = "set",
description = "Set nickname for given device. Give device index from nick list, or current nickname."
2020-08-24 18:50:29 +02:00
)]
pub struct NickSetOpt {
#[argh(positional, description = "the device index or nickname")]
pub device: String,
2020-08-24 19:05:34 +02:00
#[argh(positional, description = "the new nickname for the device")]
2020-08-24 18:50:29 +02:00
pub nickname: String,
}
2020-08-24 23:14:18 +02:00
#[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 {
2020-08-25 21:30:13 +02:00
Tag(GetTagOpt),
Tags(GetTagsOpt),
2020-08-24 23:14:18 +02:00
States(GetStatesOpt),
Locations(GetLocationsOpt),
}
2020-08-25 21:30:13 +02:00
#[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 {}
2020-08-24 23:14:18 +02:00
#[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>,
2020-08-24 23:14:18 +02:00
}