use clap::{Args, Parser, Subcommand};
use std::time::Duration;
#[derive(Parser)]
#[command(
name = "openseries",
version,
disable_version_flag = true,
disable_help_subcommand = true
)]
pub(crate) struct Cli {
#[arg(
short = 'v',
long = "version",
action = clap::ArgAction::Version,
help = "Prints version information"
)]
pub(crate) version: (),
#[arg(
long,
default_value_t = 2_000,
value_name = "MILLISECONDS",
global = true
)]
pub(crate) timeout_ms: u64,
#[command(subcommand)]
pub(crate) command: Option<Command>,
}
impl Cli {
pub(crate) fn discovery_options(&self) -> openseries::DiscoveryOptions {
openseries::DiscoveryOptions::default().with_timeout(Duration::from_millis(self.timeout_ms))
}
}
#[derive(Subcommand)]
pub(crate) enum Command {
Battery(JsonArgs),
Status(DeviceJsonArgs),
Interactive,
Devices {
#[command(subcommand)]
command: DevicesCommand,
},
Headset {
#[command(subcommand)]
command: HeadsetCommand,
},
Mouse {
#[command(subcommand)]
command: MouseCommand,
},
}
#[derive(Subcommand)]
pub(crate) enum DevicesCommand {
List(JsonArgs),
}
#[derive(Subcommand)]
pub(crate) enum HeadsetCommand {
Battery(DeviceJsonArgs),
Chatmix(DeviceJsonArgs),
Sidetone {
level: i32,
#[command(flatten)]
device: DeviceArg,
},
InactiveTime {
minutes: i32,
#[command(flatten)]
device: DeviceArg,
},
MicrophoneVolume {
volume: i32,
#[command(flatten)]
device: DeviceArg,
},
MicrophoneMuteLed {
brightness: i32,
#[command(flatten)]
device: DeviceArg,
},
VolumeLimiter {
state: String,
#[command(flatten)]
device: DeviceArg,
},
Bluetooth {
#[command(subcommand)]
command: BluetoothCommand,
},
Equalizer {
#[command(subcommand)]
command: EqualizerCommand,
},
}
#[derive(Subcommand)]
pub(crate) enum BluetoothCommand {
PowerOn {
state: String,
#[command(flatten)]
device: DeviceArg,
},
CallVolume {
mode: String,
#[command(flatten)]
device: DeviceArg,
},
}
#[derive(Subcommand)]
pub(crate) enum EqualizerCommand {
Preset {
preset: String,
#[command(flatten)]
device: DeviceArg,
},
Set {
bands: String,
#[command(flatten)]
device: DeviceArg,
},
Parametric {
bands: String,
#[command(flatten)]
device: DeviceArg,
},
}
#[derive(Subcommand)]
pub(crate) enum MouseCommand {
Battery(DeviceJsonArgs),
Sensitivity {
dpi_presets: String,
#[command(flatten)]
device: DeviceArg,
},
PollingRate {
hz: i32,
#[command(flatten)]
device: DeviceArg,
},
Color {
zone: String,
color: String,
#[command(flatten)]
device: DeviceArg,
},
SleepTimer {
minutes: i32,
#[command(flatten)]
device: DeviceArg,
},
}
#[derive(Args, Default)]
pub(crate) struct DeviceArg {
#[arg(short = 'd', long = "device", value_name = "ID")]
pub(crate) device: Option<String>,
}
#[derive(Args, Default)]
pub(crate) struct JsonArgs {
#[arg(long)]
pub(crate) json: bool,
}
#[derive(Args, Default)]
pub(crate) struct DeviceJsonArgs {
#[command(flatten)]
pub(crate) device: DeviceArg,
#[arg(long)]
pub(crate) json: bool,
}