You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main.rs
+33-17Lines changed: 33 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,17 @@
2
2
externcrate log;
3
3
externcrate pretty_env_logger;
4
4
5
-
use anyhow::{bail,Context,Result};
5
+
use anyhow::{Context,Result};
6
6
use clap::Parser;
7
7
use git2::Repository;
8
8
9
9
mod commits;
10
+
mod linting_error;
11
+
mod linting_results;
12
+
mod output;
10
13
11
14
usecrate::commits::Commits;
15
+
usecrate::output::Output;
12
16
13
17
constERROR_EXIT_CODE:i32 = 1;
14
18
@@ -27,6 +31,13 @@ pub(crate) struct Arguments {
27
31
)]
28
32
pub(crate)verbose:bool,
29
33
34
+
#[arg(
35
+
long,
36
+
default_value = "default",
37
+
help = "Specifies the format for outputting results, acceptable values are quiet, default, and pretty."
38
+
)]
39
+
pub(crate)output:Output,
40
+
30
41
#[arg(
31
42
help = "The Git reference from where to start taking the range of commits from till HEAD to lint. The range is inclusive of HEAD and exclusive of the provided reference.",
32
43
default_value = "origin/HEAD"
@@ -47,29 +58,34 @@ fn main() {
47
58
info!("Version {}.", env!("CARGO_PKG_VERSION"));
48
59
debug!("The command line arguments provided are {arguments:?}.");
49
60
50
-
ifletErr(err) = run(arguments){
51
-
error!("{err:?}");
52
-
std::process::exit(ERROR_EXIT_CODE);
61
+
matchrun(arguments){
62
+
Ok(exit_code) => std::process::exit(exit_code),
63
+
Err(err) => {
64
+
error!("{err:?}");
65
+
std::process::exit(ERROR_EXIT_CODE);
66
+
}
53
67
}
54
68
}
55
69
56
-
fnrun(arguments:Arguments) -> Result<()>{
70
+
fnrun(arguments:Arguments) -> Result<i32>{
57
71
let repository = Repository::open_from_env().context("Unable to open the Git repository.")?;
58
72
let commits = Commits::from_git(&repository, arguments.from)?;
59
73
60
-
if commits.contains_merge_commits(){
61
-
bail!("Contains merge commits.");
62
-
}
63
-
64
-
ifletSome(max_commits) = arguments.max_commits{
65
-
if commits.len() > max_commits {
66
-
bail!(format!(
67
-
"Exceeded the maximum number of commits {:?} with {:?} commits.",
0 commit comments