From 65b3f667532685f854c699ddd264d326599cf7e5 Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Fri, 1 Apr 2016 02:07:44 -0300 Subject: [PATCH] imp(srs/args): Added longest_filter to AnyArg trait This function allows providing an extra filter to remove elements when finding the longest element. --- src/app/mod.rs | 1 + src/args/any_arg.rs | 1 + src/args/arg_builder/flag.rs | 1 + src/args/arg_builder/option.rs | 1 + src/args/arg_builder/positional.rs | 1 + 5 files changed, 5 insertions(+) diff --git a/src/app/mod.rs b/src/app/mod.rs index 17ff3d5f..04170c8c 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -936,6 +936,7 @@ impl<'n, 'e> AnyArg<'n, 'e> for App<'n, 'e> { fn takes_value(&self) -> bool { true } fn help(&self) -> Option<&'e str> { self.p.meta.about } fn default_val(&self) -> Option<&'n str> { None } + fn longest_filter(&self) -> bool { true } } impl<'n, 'e> fmt::Display for App<'n, 'e> { diff --git a/src/args/any_arg.rs b/src/args/any_arg.rs index a4fc5ec7..16f3d001 100644 --- a/src/args/any_arg.rs +++ b/src/args/any_arg.rs @@ -25,6 +25,7 @@ pub trait AnyArg<'n, 'e> { fn val_names(&self) -> Option<&VecMap<&'e str>>; fn help(&self) -> Option<&'e str>; fn default_val(&self) -> Option<&'n str>; + fn longest_filter(&self) -> bool; } pub trait DispOrder { diff --git a/src/args/arg_builder/flag.rs b/src/args/arg_builder/flag.rs index 4f1d201e..0471246a 100644 --- a/src/args/arg_builder/flag.rs +++ b/src/args/arg_builder/flag.rs @@ -129,6 +129,7 @@ impl<'n, 'e> AnyArg<'n, 'e> for FlagBuilder<'n, 'e> { fn val_delim(&self) -> Option { None } fn help(&self) -> Option<&'e str> { self.help } fn default_val(&self) -> Option<&'n str> { None } + fn longest_filter(&self) -> bool { self.long.is_some() } } impl<'n, 'e> DispOrder for FlagBuilder<'n, 'e> { diff --git a/src/args/arg_builder/option.rs b/src/args/arg_builder/option.rs index f150802a..01c05f06 100644 --- a/src/args/arg_builder/option.rs +++ b/src/args/arg_builder/option.rs @@ -193,6 +193,7 @@ impl<'n, 'e> AnyArg<'n, 'e> for OptBuilder<'n, 'e> { fn takes_value(&self) -> bool { true } fn help(&self) -> Option<&'e str> { self.help } fn default_val(&self) -> Option<&'n str> { self.default_val } + fn longest_filter(&self) -> bool { true } } impl<'n, 'e> DispOrder for OptBuilder<'n, 'e> { diff --git a/src/args/arg_builder/positional.rs b/src/args/arg_builder/positional.rs index 81fe46ca..c08980f2 100644 --- a/src/args/arg_builder/positional.rs +++ b/src/args/arg_builder/positional.rs @@ -180,6 +180,7 @@ impl<'n, 'e> AnyArg<'n, 'e> for PosBuilder<'n, 'e> { fn takes_value(&self) -> bool { true } fn help(&self) -> Option<&'e str> { self.help } fn default_val(&self) -> Option<&'n str> { self.default_val } + fn longest_filter(&self) -> bool { true } } impl<'n, 'e> DispOrder for PosBuilder<'n, 'e> {