@@ -3,7 +3,7 @@ use std::borrow::Cow;
33use nom:: {
44 branch:: alt,
55 bytes:: complete:: { is_not, tag} ,
6- character:: complete:: { alphanumeric1, anychar, char, multispace0, multispace1} ,
6+ character:: complete:: { alphanumeric1, anychar, char, digit1 , multispace0, multispace1} ,
77 combinator:: { all_consuming, map, recognize, value, verify} ,
88 error:: { ContextError , ParseError } ,
99 multi:: { fold_many0, many1_count, separated_list1} ,
@@ -235,6 +235,28 @@ fn jmespath<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
235235 Ok ( ( remaining, FilterAttribute :: JMESPath ( value) ) )
236236}
237237
238+ fn positive_integer < ' a , E : ParseError < & ' a str > + ContextError < & ' a str > > (
239+ s : & ' a str ,
240+ ) -> IResult < & ' a str , usize , E > {
241+ let ( remaining, digits) = digit1 ( s) ?;
242+ let n = digits
243+ . parse :: < usize > ( )
244+ . map_err ( |_| nom:: Err :: Error ( E :: from_error_kind ( s, nom:: error:: ErrorKind :: Digit ) ) ) ?;
245+ Ok ( ( remaining, n) )
246+ }
247+
248+ fn limit < ' a , E : ParseError < & ' a str > + ContextError < & ' a str > > (
249+ s : & ' a str ,
250+ ) -> IResult < & ' a str , FilterAttribute < ' a > , E > {
251+ let ( remaining, ( _, value) ) = separated_pair (
252+ alt ( ( tag ( "limit" ) , tag ( "lim" ) ) ) ,
253+ char ( ':' ) ,
254+ positive_integer,
255+ )
256+ . parse ( s) ?;
257+ Ok ( ( remaining, FilterAttribute :: Limit ( value) ) )
258+ }
259+
238260fn specified_daemonset < ' a , E : ParseError < & ' a str > + ContextError < & ' a str > > (
239261 s : & ' a str ,
240262) -> IResult < & ' a str , FilterAttribute < ' a > , E > {
@@ -349,6 +371,7 @@ fn attribute<'a, E: ParseError<&'a str> + ContextError<&'a str>>(
349371 specified_statefulset,
350372 field_selector,
351373 label_selector,
374+ limit,
352375 pod,
353376 exclude_pod,
354377 container,
@@ -714,6 +737,18 @@ mod tests {
714737 assert_eq ! ( remaining, "" ) ;
715738 }
716739
740+ #[ rstest]
741+ #[ case( "limit:5000" , 5000 ) ]
742+ #[ case( "lim:5000" , 5000 ) ]
743+ #[ case( "limit:1" , 1 ) ]
744+ #[ case( "limit:100000" , 100000 ) ]
745+ fn limit ( #[ case] query : & str , #[ case] expected : usize ) {
746+ let ( remaining, actual) = super :: limit :: < Error < _ > > ( query) . unwrap ( ) ;
747+
748+ assert_eq ! ( actual, FilterAttribute :: Limit ( expected) ) ;
749+ assert_eq ! ( remaining, "" ) ;
750+ }
751+
717752 #[ rustfmt:: skip]
718753 #[ rstest]
719754 #[ case( "pod:hoge" , FilterAttribute :: Pod ( "hoge" . into( ) ) ) ]
@@ -735,6 +770,8 @@ mod tests {
735770 #[ case( "jmespath:message" , FilterAttribute :: JMESPath ( "message" . into( ) ) ) ]
736771 #[ case( "jmes:level" , FilterAttribute :: JMESPath ( "level" . into( ) ) ) ]
737772 #[ case( "jm:data.id" , FilterAttribute :: JMESPath ( "data.id" . into( ) ) ) ]
773+ #[ case( "limit:5000" , FilterAttribute :: Limit ( 5000 ) ) ]
774+ #[ case( "lim:1000" , FilterAttribute :: Limit ( 1000 ) ) ]
738775 fn attribute ( #[ case] query : & str , #[ case] expected : FilterAttribute ) {
739776 let ( remaining, actual) = super :: attribute :: < Error < _ > > ( query) . unwrap ( ) ;
740777
@@ -763,6 +800,7 @@ mod tests {
763800 "statefulset/app" ,
764801 "jq:.message" ,
765802 "jmespath:data.id" ,
803+ "limit:5000" ,
766804 " " ,
767805 ]
768806 . join ( " " ) ;
@@ -787,6 +825,7 @@ mod tests {
787825 FilterAttribute :: Resource ( SpecifiedResource :: StatefulSet ( "app" ) ) ,
788826 FilterAttribute :: Jq ( ".message" . into( ) ) ,
789827 FilterAttribute :: JMESPath ( "data.id" . into( ) ) ,
828+ FilterAttribute :: Limit ( 5000 ) ,
790829 ] ;
791830
792831 assert_eq ! ( actual, expected) ;
0 commit comments