1- #![ deny( missing_docs) ]
2-
3- //! # git-semver-tags
4- //!
5- //! Get all git semver tags of your repository in reverse chronological order
6- //!
7- //! ## Install
8- //!
9- //! Run
10- //! ``` Console
11- //! $ cargo install git-semver-tags
12- //! ```
13- //!
14- //! ## Usage
15- //!
16- //!
17- //! By default, it runs check. You can easily override this, though:
18- //!
19- //! ``` Console
20- //! $ git-semver-tags [OPTIONS]
21- //! ```
22- //!
23- //! A few examples:
24- //!
25- //!
26- //! ``` Console
27- //! ## Run get all tags
28- //! $ git-semver-tags
29- //!
30- //! ## Run to get lerna tag
31- //! $ git-semver-tags --lerna
32- //!
33- //! ## Run the lerna tag to get the specified package name
34- //! $ git-semver-tags --lerna --package <package>
35- //!
36- //! ## Runs get tag for the specified prefix
37- //! $ git-semver-tags --tag-prefix <prefix>
38- //!
39- //! ## Run get to ignore unstable tag
40- //! $ git-semver-tags --skip-unstable
41- //!
42- //! ## Run get label under the specified path
43- //! $ git-semver-tags --cwd <cwd>
44- //! ```
45- //!
46- //!
47- //! There's a lot more you can do! Here's a copy of the help:
48- //!
49- //! ``` Console
50- //! Get all git semver tags of your repository in reverse chronological order
51- //!
52- //! Usage: git-semver-tags [OPTIONS]
53- //!
54- //! Options:
55- //! --lerna parse lerna style git tags
56- //! --package <package> when listing lerna style tags, filter by a package
57- //! --tag-prefix <prefix> prefix to remove from the tags during their processing
58- //! --cwd <cwd> the current path where the command was run
59- //! --skip-unstable ignore unstable labels
60- //! -h, --help Print help information
61- //! -V, --version Print version information
62- //!
63- //! ```
64- //!
1+ #![ forbid( unsafe_code) ]
2+ #![ cfg_attr( docsrs, feature( doc_cfg) ) ]
3+ #![ deny( private_in_public, unreachable_pub, missing_docs, rust_2018_idioms) ]
4+ #![ doc = include_str ! ( "../README.md" ) ]
655
666use lazy_static:: lazy_static;
677use regex:: Regex ;
@@ -72,19 +12,19 @@ mod cli;
7212mod macros;
7313pub use cli:: Args ;
7414
75- fn is_lerna_tag < ' a > ( tag : & ' a str , pkg : & Option < String > ) -> bool {
15+ fn is_lerna_tag ( tag : & str , pkg : & Option < String > ) -> bool {
7616 lazy_static ! {
7717 static ref RE : Regex = format_regex!( r"^.+@[0-9]+\.[0-9]+\.[0-9]+(-.+)?$" ) ;
7818 }
7919 if let Some ( pkg) = pkg {
8020 return format_regex ! ( r"^{}@" , pkg) . is_match ( tag) ;
81- } else {
82- return RE . is_match ( tag) ;
8321 }
22+
23+ RE . is_match ( tag)
8424}
8525
8626fn semver_valid ( version : & str ) -> bool {
87- let version = if version. starts_with ( "v" ) {
27+ let version = if version. starts_with ( 'v' ) {
8828 version. get ( 1 ..) . unwrap ( )
8929 } else {
9030 version
@@ -93,7 +33,7 @@ fn semver_valid(version: &str) -> bool {
9333}
9434
9535/// List the git tags in the project
96- ///
36+ ///
9737/// # Examples
9838///
9939/// ```no_run
@@ -138,8 +78,8 @@ pub fn captures(args: &Args) -> Vec<String> {
13878 }
13979 let output = String :: from_utf8 ( output. stdout ) . expect ( "the stdout convert to String fail" ) ;
14080 return output
141- . split ( " \n " )
142- . map ( |decorations| {
81+ . split ( '\n' )
82+ . flat_map ( |decorations| {
14383 TAG_RE
14484 . captures_iter ( decorations)
14585 . filter_map ( |cap| {
@@ -150,7 +90,7 @@ pub fn captures(args: &Args) -> Vec<String> {
15090 }
15191
15292 if * lerna {
153- if is_lerna_tag ( tag, & package) {
93+ if is_lerna_tag ( tag, package) {
15494 return Some ( tag. to_string ( ) ) ;
15595 }
15696 } else if let Some ( re) = tag_prefix_re. as_ref ( ) {
@@ -165,7 +105,6 @@ pub fn captures(args: &Args) -> Vec<String> {
165105 } )
166106 . collect :: < Vec < _ > > ( )
167107 } )
168- . flatten ( )
169108 . collect ( ) ;
170109}
171110
0 commit comments