diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-01-07 15:22:20 +0000 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-01-07 15:22:20 +0000 |
commit | 8e29cb575f4534c4c723699164db7315a970f1ec (patch) | |
tree | f0484e7da91533c1ce3eafbf69d3c6108a17f7b8 /src/arg_util.rs | |
parent | 77921f888f3106e961e1936fd6a42a9625efe6bf (diff) | |
download | nitrocli-8e29cb575f4534c4c723699164db7315a970f1ec.tar.gz nitrocli-8e29cb575f4534c4c723699164db7315a970f1ec.tar.bz2 |
Remove unused code after structopt transition
In the previous patches, we replaced argparse with structopt and removed
the argparse dependency. This patch removes the code that was only
needed for argparse.
Diffstat (limited to 'src/arg_util.rs')
-rw-r--r-- | src/arg_util.rs | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/src/arg_util.rs b/src/arg_util.rs index dbb9ce1..52d1020 100644 --- a/src/arg_util.rs +++ b/src/arg_util.rs @@ -33,35 +33,6 @@ macro_rules! Command { )* } - impl ::std::convert::AsRef<str> for $name { - fn as_ref(&self) -> &'static str { - match *self { - $( - $name::$var(_) => $str, - )* - } - } - } - - impl ::std::fmt::Display for $name { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!(f, "{}", self.as_ref()) - } - } - - impl ::std::str::FromStr for $name { - type Err = &'static str; - - fn from_str(s: &str) -> ::std::result::Result<Self, Self::Err> { - match s { - $( - $str => Ok($name::$var(::std::default::Default::default())), - )* - _ => Err("[error]"), - } - } - } - #[allow(unused_qualifications)] impl $name { fn execute( @@ -75,62 +46,6 @@ macro_rules! Command { } } } - - impl_default!($name => $( $name::$var(::std::default::Default::default()) , )*); - }; - ( $name:ident, [ $( $var:ident => ($str:expr, $exec:expr), ) *] ) => { - #[derive(Debug, PartialEq, ::structopt::StructOpt)] - pub enum $name { - $( - $var, - )* - } - - impl ::std::convert::AsRef<str> for $name { - fn as_ref(&self) -> &'static str { - match *self { - $( - $name::$var => $str, - )* - } - } - } - - impl ::std::fmt::Display for $name { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!(f, "{}", self.as_ref()) - } - } - - impl ::std::str::FromStr for $name { - type Err = &'static str; - - fn from_str(s: &str) -> ::std::result::Result<Self, Self::Err> { - match s { - $( - $str => Ok($name::$var), - )* - _ => Err("[error]"), - } - } - } - - #[allow(unused_qualifications)] - impl $name { - fn execute( - self, - ctx: &mut crate::args::ExecCtx<'_>, - args: ::std::vec::Vec<::std::string::String>, - ) -> crate::Result<()> { - match self { - $( - $name::$var => $exec(ctx, args), - )* - } - } - } - - impl_default!($name => $( $name::$var , )*); }; } @@ -207,39 +122,9 @@ macro_rules! enum_int { } } } - - impl_default!($name => $( $name::$var , )*); - - }; -} - -macro_rules! impl_default { - ( $name:ident => $def:expr , $( $other:expr , ) *) => { - impl ::std::default::Default for $name { - fn default() -> Self { - $def - } - } }; } -/// A macro for formatting the variants of an enum (as created by the -/// Enum!{} macro) ready to be used in a help text. The supplied `fmt` -/// needs to contain the named parameter `{variants}`, which will be -/// replaced with a generated version of the enum's variants. -macro_rules! fmt_enum { - ( $enm:ident ) => {{ - fmt_enum!($enm.all()) - }}; - ( $all:expr ) => {{ - $all - .iter() - .map(::std::convert::AsRef::as_ref) - .collect::<::std::vec::Vec<_>>() - .join("|") - }}; -} - #[cfg(test)] mod tests { Enum! {Command, [ |