Skip to content

Commit 99254d2

Browse files
committed
style: fmt
1 parent 59700f3 commit 99254d2

File tree

3 files changed

+78
-74
lines changed

3 files changed

+78
-74
lines changed

.github/workflows/CI.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
10+
jobs:
11+
test:
12+
name: cargo test (${{ matrix.os }})
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os:
17+
- ubuntu-latest
18+
- macos-latest
19+
- windows-latest
20+
runs-on: ${{ matrix.os }}
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: dtolnay/rust-toolchain@v1
24+
with:
25+
toolchain: nightly
26+
- name: Test cases
27+
run: |
28+
cargo test --workspace --all --verbose
29+
30+
clippy:
31+
name: cargo clippy
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v3
35+
- uses: dtolnay/rust-toolchain@v1
36+
with:
37+
toolchain: nightly
38+
components: clippy
39+
- name: Check Clippy
40+
run: |
41+
cargo clippy --workspace --all-targets
42+
43+
fmt:
44+
name: cargo fmt
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v3
48+
- uses: dtolnay/rust-toolchain@v1
49+
with:
50+
toolchain: stable
51+
components: rustfmt
52+
- name: Check formatting
53+
run: |
54+
cargo fmt --all -- --check
55+
56+
docs:
57+
name: cargo doc
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v3
61+
- uses: dtolnay/rust-toolchain@v1
62+
with:
63+
toolchain: nightly
64+
- name: Check documenting
65+
run: |
66+
RUSTDOCFLAGS="-D warnings --cfg docsrs" cargo doc --workspace --all-features --no-deps

src/cli.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub struct Args {
2626
}
2727

2828
impl Args {
29-
3029
/// specify the lerna tag
3130
pub fn lerna(&mut self) -> &mut Args {
3231
self.lerna = true;

src/lib.rs

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,7 @@
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

666
use lazy_static::lazy_static;
677
use regex::Regex;
@@ -72,19 +12,19 @@ mod cli;
7212
mod macros;
7313
pub 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

8626
fn 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

Comments
 (0)