From cead6e8872e7312284031feee81d91102656fc7d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 20 Oct 2019 00:46:33 -0400 Subject: also move the flag definitions into the config reader --- src/cmd/play.rs | 6 +---- src/cmd/record.rs | 16 +++----------- src/cmd/server.rs | 28 +----------------------- src/cmd/stream.rs | 27 +++-------------------- src/cmd/watch.rs | 18 +-------------- src/config.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 86 deletions(-) diff --git a/src/cmd/play.rs b/src/cmd/play.rs index 7eae765..2e41816 100644 --- a/src/cmd/play.rs +++ b/src/cmd/play.rs @@ -24,11 +24,7 @@ impl crate::config::Config for Config { } pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { - app.about("Play recorded terminal sessions").arg( - clap::Arg::with_name("filename") - .long("filename") - .takes_value(true), - ) + crate::config::Ttyrec::cmd(app.about("Play recorded terminal sessions")) } pub fn config(config: config::Config) -> Box { diff --git a/src/cmd/record.rs b/src/cmd/record.rs index 3e19ed8..f36f161 100644 --- a/src/cmd/record.rs +++ b/src/cmd/record.rs @@ -32,19 +32,9 @@ impl crate::config::Config for Config { } pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { - app.about("Record a terminal session to a file") - .arg( - clap::Arg::with_name("filename") - .long("filename") - .takes_value(true), - ) - .arg( - clap::Arg::with_name("buffer-size") - .long("buffer-size") - .takes_value(true), - ) - .arg(clap::Arg::with_name("command").index(1)) - .arg(clap::Arg::with_name("args").index(2).multiple(true)) + crate::config::Command::cmd(crate::config::Ttyrec::cmd( + app.about("Record a terminal session to a file"), + )) } pub fn config(config: config::Config) -> Box { diff --git a/src/cmd/server.rs b/src/cmd/server.rs index ea238ba..6a937c7 100644 --- a/src/cmd/server.rs +++ b/src/cmd/server.rs @@ -46,33 +46,7 @@ impl crate::config::Config for Config { } pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { - app.about("Run a teleterm server") - .arg( - clap::Arg::with_name("address") - .long("address") - .takes_value(true), - ) - .arg( - clap::Arg::with_name("buffer-size") - .long("buffer-size") - .takes_value(true), - ) - .arg( - clap::Arg::with_name("read-timeout") - .long("read-timeout") - .takes_value(true), - ) - .arg( - clap::Arg::with_name("tls-identity-file") - .long("tls-identity-file") - .takes_value(true), - ) - .arg( - clap::Arg::with_name("allowed-login-methods") - .long("allowed-login-methods") - .use_delimiter(true) - .takes_value(true), - ) + crate::config::Server::cmd(app.about("Run a teleterm server")) } pub fn config(config: config::Config) -> Box { diff --git a/src/cmd/stream.rs b/src/cmd/stream.rs index 14f4fac..e013660 100644 --- a/src/cmd/stream.rs +++ b/src/cmd/stream.rs @@ -86,30 +86,9 @@ impl crate::config::Config for Config { } pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { - app.about("Stream your terminal") - .arg( - clap::Arg::with_name("login-plain") - .long("login-plain") - .takes_value(true), - ) - .arg( - clap::Arg::with_name("login-recurse-center") - .long("login-recurse-center") - .conflicts_with("login-plain"), - ) - .arg( - clap::Arg::with_name("address") - .long("address") - .takes_value(true), - ) - .arg(clap::Arg::with_name("tls").long("tls")) - .arg( - clap::Arg::with_name("buffer-size") - .long("buffer-size") - .takes_value(true), - ) - .arg(clap::Arg::with_name("command").index(1)) - .arg(clap::Arg::with_name("args").index(2).multiple(true)) + crate::config::Client::cmd(crate::config::Command::cmd( + app.about("Stream your terminal"), + )) } pub fn config(config: config::Config) -> Box { diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index 62ef2e0..4bf9fdd 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -82,23 +82,7 @@ impl crate::config::Config for Config { } pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { - app.about("Watch teleterm streams") - .arg( - clap::Arg::with_name("login-plain") - .long("login-plain") - .takes_value(true), - ) - .arg( - clap::Arg::with_name("login-recurse-center") - .long("login-recurse-center") - .conflicts_with("login-plain"), - ) - .arg( - clap::Arg::with_name("address") - .long("address") - .takes_value(true), - ) - .arg(clap::Arg::with_name("tls").long("tls")) + crate::config::Client::cmd(app.about("Watch teleterm streams")) } pub fn config(config: config::Config) -> Box { diff --git a/src/config.rs b/src/config.rs index 8fc2596..d3352d9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -70,6 +70,25 @@ impl Client { &self.connect_address.1 } + pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { + app.arg( + clap::Arg::with_name("login-plain") + .long("login-plain") + .takes_value(true), + ) + .arg( + clap::Arg::with_name("login-recurse-center") + .long("login-recurse-center") + .conflicts_with("login-plain"), + ) + .arg( + clap::Arg::with_name("address") + .long("address") + .takes_value(true), + ) + .arg(clap::Arg::with_name("tls").long("tls")) + } + pub fn merge_args<'a>( &mut self, matches: &clap::ArgMatches<'a>, @@ -192,6 +211,35 @@ pub struct Server { } impl Server { + pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { + app.arg( + clap::Arg::with_name("address") + .long("address") + .takes_value(true), + ) + .arg( + clap::Arg::with_name("buffer-size") + .long("buffer-size") + .takes_value(true), + ) + .arg( + clap::Arg::with_name("read-timeout") + .long("read-timeout") + .takes_value(true), + ) + .arg( + clap::Arg::with_name("tls-identity-file") + .long("tls-identity-file") + .takes_value(true), + ) + .arg( + clap::Arg::with_name("allowed-login-methods") + .long("allowed-login-methods") + .use_delimiter(true) + .takes_value(true), + ) + } + pub fn merge_args<'a>( &mut self, matches: &clap::ArgMatches<'a>, @@ -358,6 +406,15 @@ pub struct Command { } impl Command { + pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { + app.arg( + clap::Arg::with_name("buffer-size") + .long("buffer-size") + .takes_value(true), + ) + .arg(clap::Arg::with_name("command").index(1)) + .arg(clap::Arg::with_name("args").index(2).multiple(true)) + } pub fn merge_args<'a>( &mut self, matches: &clap::ArgMatches<'a>, @@ -407,6 +464,14 @@ pub struct Ttyrec { } impl Ttyrec { + pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { + app.arg( + clap::Arg::with_name("filename") + .long("filename") + .takes_value(true), + ) + } + pub fn merge_args<'a>( &mut self, matches: &clap::ArgMatches<'a>, -- cgit v1.2.3-54-g00ecf