Skip to content

Commit

Permalink
Merge branch 'cli'
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Zaunseder committed Mar 6, 2024
2 parents 91bb190 + 6775f2f commit 3719d74
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 67 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
name: Rust
name: CI

on:
push:
branches: [ "main" ]
branches: ["*"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Lint
run: cargo clippy && cargo fmt --check
- name: Run tests
run: cargo test --verbose
113 changes: 113 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ keywords = ["cli", "commitlint", "git", "lint", "commit"]
categories = ["command-line-utilities", "development-tools"]

[dependencies]
clap = { version = "4.5.1", features = ["derive", "string"] }
config = "0.13.4"
miette = { version = "5.10.0", features = ["fancy"] }
pest = "2.7.6"
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ cargo install commitguard

## Usage

> Not quite yet, but it will be something like this:
```sh
echo "foo" | commitguard
echo "feat(myscope): add new feature" | commitguard
```

## Todos/Ideas:
Expand Down
2 changes: 1 addition & 1 deletion src/commit.pest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commit = { SOI ~ header ~ body? ~ footer? ~ EOI }
commit = { SOI ~ header ~ body? ~ footer? ~ NEWLINE* ~ EOI }

header = ${ commit_type ~ scope_with_braces? ~ "!"? ~ ":" ~ WHITE_SPACE+ ~ subject }

Expand Down
34 changes: 28 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
mod parser;
mod rules;

use std::process::ExitCode;
use std::{
env::current_dir,
io::{stdin, Read},
path::PathBuf,
process::ExitCode,
};

use clap::Parser;
use miette::GraphicalReportHandler;
use parser::parse_commit;

/// Commit lint
#[derive(clap::Parser, Debug)]
#[command(version, about, long_about = None)]
struct Cli {
/// Path to the config file
#[arg(short, long, default_value = "commitguard.config")]
config_name: String,

/// Current working directory
#[arg(long, default_value = current_dir().unwrap_or_else(|_e| PathBuf::from("/")).into_os_string())]
cwd: PathBuf,
}

fn main() -> ExitCode {
let commit_message =
"feat(nice): add cool feature\n\nsome body\n\nsecond body line\n\nsome footer";
let args = Cli::parse();

// read commit from stdin
let mut buffer = String::new();
stdin().read_to_string(&mut buffer).unwrap_or(0);
let commit = parse_commit(&buffer);

let commit = parse_commit(&commit_message);
println!("{:#?}", commit);
let config_path = args.cwd.join(args.config_name);
let lint_result = rules::run(&commit, config_path);

let lint_result = rules::run(&commit);
let report_handler = GraphicalReportHandler::new();

if lint_result.has_warnings() {
Expand Down
Loading

0 comments on commit 3719d74

Please sign in to comment.