@@ -25,12 +25,10 @@ fn is_lerna_tag(tag: &str, pkg: &Option<String>) -> bool {
2525 RE . is_match ( tag)
2626}
2727
28- fn semver_valid ( version : & str ) -> bool {
29- let version = if version. starts_with ( 'v' ) {
30- version. get ( 1 ..) . unwrap ( )
31- } else {
32- version
33- } ;
28+ fn semver_valid ( mut version : & str ) -> bool {
29+ if version. starts_with ( 'v' ) {
30+ version = & version[ 1 ..]
31+ }
3432 semver:: Version :: parse ( version) . is_ok ( )
3533}
3634
@@ -69,7 +67,7 @@ pub fn self_upgrade(is_test: bool) -> Result<(), Box<dyn std::error::Error>> {
6967/// Ok(())
7068/// }
7169/// ```
72- pub fn captures ( args : & Args ) -> Vec < String > {
70+ pub fn captures ( args : Args ) -> Vec < String > {
7371 lazy_static ! {
7472 static ref TAG_RE : Regex = format_regex!( r"tag:\s*(.+?)[,)]" ) ;
7573 static ref UNSTABLE_TAG_RE : Regex = format_regex!( r".+-\w+\.\d+$" ) ;
@@ -84,50 +82,41 @@ pub fn captures(args: &Args) -> Vec<String> {
8482 ..
8583 } = args;
8684
87- let tag_prefix_re = tag_prefix
88- . as_ref ( )
89- . map ( |prefix| format_regex ! ( r"^{}(.*)" , prefix) ) ;
85+ let tag_prefix_re = tag_prefix. map ( |prefix| format_regex ! ( r"^{}(.*)" , prefix) ) ;
9086
9187 let mut binding = Command :: new ( "git" ) ;
9288 binding. args ( [ "log" , "--decorate" , "--no-color" ] ) ;
9389 if let Some ( cwd) = cwd {
9490 binding. current_dir ( cwd) ;
9591 }
96- let output = binding. output ( ) . expect ( "failed to execute process" ) ;
92+ let output = binding. output ( ) . expect ( "success to execute process" ) ;
9793 if !output. stderr . is_empty ( ) {
98- std:: io:: stderr ( ) . write_all ( & output. stderr ) . unwrap ( ) ;
94+ std:: io:: stderr ( )
95+ . write_all ( & output. stderr )
96+ . expect ( "expose error msg" ) ;
9997 std:: process:: exit ( 1 ) ;
10098 }
10199 let output = String :: from_utf8 ( output. stdout ) . expect ( "the stdout convert to String fail" ) ;
102100 return output
103101 . split ( '\n' )
104- . flat_map ( |decorations| {
105- TAG_RE
106- . captures_iter ( decorations)
107- . filter_map ( |cap| {
108- let tag = & cap[ 1 ] ;
109-
110- if * skip_unstable && UNSTABLE_TAG_RE . is_match ( tag) {
111- return None ;
112- }
113-
114- if * lerna {
115- if is_lerna_tag ( tag, package) {
116- return Some ( tag. to_string ( ) ) ;
117- }
118- } else if let Some ( re) = tag_prefix_re. as_ref ( ) {
119- let captures = re. captures ( tag) ;
120- if matches ! ( captures, Some ( cap) if semver_valid( & cap[ 1 ] ) ) {
121- return Some ( tag. to_string ( ) ) ;
122- }
123- } else if semver_valid ( tag) {
124- return Some ( tag. to_string ( ) ) ;
125- }
126- None
127- } )
128- . collect :: < Vec < _ > > ( )
102+ . flat_map ( |decorations| TAG_RE . captures_iter ( decorations) )
103+ . filter_map ( |cap| match & cap[ 1 ] {
104+ tag if skip_unstable && UNSTABLE_TAG_RE . is_match ( tag) => None ,
105+ tag if lerna => match is_lerna_tag ( tag, & package) {
106+ true => Some ( tag. to_owned ( ) ) ,
107+ false => None ,
108+ } ,
109+ tag if tag_prefix_re. is_some ( ) => {
110+ let re = tag_prefix_re. as_ref ( ) . unwrap ( ) ;
111+ match re. captures ( tag) {
112+ Some ( cap) if semver_valid ( & cap[ 1 ] ) => Some ( tag. to_owned ( ) ) ,
113+ _ => None ,
114+ }
115+ }
116+ tag if semver_valid ( tag) => Some ( tag. to_owned ( ) ) ,
117+ _ => None ,
129118 } )
130- . collect ( ) ;
119+ . collect :: < Vec < _ > > ( ) ;
131120}
132121
133122#[ cfg( test) ]
0 commit comments