From 8b6c0900d6d301eb2791a7300acfdf1cb7fcce8d Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 4 Sep 2018 19:30:02 +0200 Subject: Separate CLI + auto-generate completion at build time --- src/cli.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 60 +++--------------------------------------------------------- 2 files changed, 62 insertions(+), 57 deletions(-) create mode 100644 src/cli.rs (limited to 'src') diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..f24b222 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,59 @@ +use clap_verbosity_flag; +use clap_log_flag; +use structopt; + +#[derive(StructOpt, Debug)] +#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))] +/// Hello World! How are you doing? +pub struct Cli { + #[structopt(flatten)] + pub verbose: clap_verbosity_flag::Verbosity, + #[structopt(flatten)] + pub log: clap_log_flag::Log, + #[structopt(short = "s")] + /// Use the given sink. + /// + /// By default it will use the last equalized sink it finds + pub sink: Option, + #[structopt(subcommand)] + pub cmd: Command, +} + +#[derive(StructOpt, Debug)] +pub enum Command { + #[structopt(name = "load",)] + /// Load and switch to a given equalizer configuration + Load(LoadCli), + #[structopt(name = "reset")] + /// Switch to a neutral equalizer + Reset(ResetCli), +} + +#[derive(StructOpt, Debug)] +pub struct LoadCli { + #[structopt(default_value = "-")] + /// The file from which to load the equalizer configuration + /// + /// If "-" is given, read the configuration from the command-line. + pub file: String, + #[structopt( + short = "f", + raw( + possible_values = "&EqualizerConfFormat::variants()", + case_insensitive = "true" + ), + default_value = "EqualizerAPO" + )] + /// The file format of the equalizer configuration + pub format: EqualizerConfFormat, +} + +arg_enum! { + #[derive(Debug)] + pub enum EqualizerConfFormat { + EqualizerAPO + } +} + +#[derive(StructOpt, Debug)] +pub struct ResetCli {} diff --git a/src/main.rs b/src/main.rs index 360117c..85d2443 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,75 +14,21 @@ extern crate structopt; extern crate lalrpop_util; +mod cli; mod dbus_api; mod parsing; mod utils; use utils::*; - use dbus_api::sink::OrgPulseAudioExtEqualizing1Equalizer; +use cli::*; + use failure::Error; use structopt::StructOpt; use std::fs::File; use std::io; -#[derive(StructOpt, Debug)] -#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))] -/// Hello World! How are you doing? -struct Cli { - #[structopt(flatten)] - verbose: clap_verbosity_flag::Verbosity, - #[structopt(flatten)] - log: clap_log_flag::Log, - #[structopt(short = "s")] - /// Use the given sink. - /// - /// By default it will use the last equalized sink it finds - sink: Option, - #[structopt(subcommand)] - cmd: Command, -} - -#[derive(StructOpt, Debug)] -enum Command { - #[structopt(name = "load",)] - /// Load and switch to a given equalizer configuration - Load(LoadCli), - #[structopt(name = "reset")] - /// Switch to a neutral equalizer - Reset(ResetCli), -} - -#[derive(StructOpt, Debug)] -struct LoadCli { - #[structopt(default_value = "-")] - /// The file from which to load the equalizer configuration - /// - /// If "-" is given, read the configuration from the command-line. - file: String, - #[structopt( - short = "f", - raw( - possible_values = "&EqualizerConfFormat::variants()", - case_insensitive = "true" - ), - default_value = "EqualizerAPO" - )] - /// The file format of the equalizer configuration - format: EqualizerConfFormat, -} - -arg_enum! { - #[derive(Debug)] - enum EqualizerConfFormat { - EqualizerAPO - } -} - -#[derive(StructOpt, Debug)] -struct ResetCli {} - #[derive(Debug)] pub struct Filter { preamp: f64, -- cgit v1.2.3