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) ]
#[ argh(description = " Tool for gathering location data from Yepzon servers. " ) ]
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) ]
pub subcommand : Subcommand ,
}
#[ 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 ) ,
2020-08-25 20:55:04 +02:00
Api ( ApiOpt ) ,
2020-08-24 18:50:29 +02:00
Nick ( NickOpt ) ,
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 " ,
2020-08-24 19:05:34 +02:00
description = " fetch locations for a given section in time. \n <device> nickname, or index from nick list. \n 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
2020-08-25 20:55:04 +02:00
#[ derive(FromArgs) ]
#[ argh(
subcommand ,
name = " api " ,
description = " check integrity of API and API-key validity "
) ]
pub struct ApiOpt { }
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 " ,
2020-08-25 20:55:04 +02:00
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 {
2020-08-25 20:55:04 +02:00
#[ 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 20:55:04 +02:00
Tags ( GetTagsOpt ) ,
2020-08-24 23:14:18 +02:00
States ( GetStatesOpt ) ,
Locations ( GetLocationsOpt ) ,
}
2020-08-25 20:55:04 +02:00
#[ 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 " ) ]
2020-08-25 20:55:04 +02:00
pub state : Option < String > ,
2020-08-24 23:14:18 +02:00
}