Skip to content

Commit a642bd8

Browse files
committed
feat: use only Rust std library
1 parent 383c300 commit a642bd8

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

.github/workflows/cd.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ jobs:
1010
name: Publishing to Cargo
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: Checkout repository
14-
uses: actions/checkout@v4
13+
- uses: actions/checkout@v4
1514

16-
- name: Install Rust toolchain
17-
uses: dtolnay/rust-toolchain@stable
15+
- uses: dtolnay/rust-toolchain@stable
1816

1917
- uses: Swatinem/rust-cache@v2
2018

.github/workflows/ci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ on:
99

1010
jobs:
1111
ci:
12-
runs-on: ubuntu-latest
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
os: [ ubuntu-latest, windows-latest, macos-latest ]
16+
1317
steps:
1418
- uses: actions/checkout@v4
1519

Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
[package]
22
name = "husky-rs"
3-
version = "0.0.1"
3+
version = "0.1.0"
44
edition = "2021"
55
description = "husky for cargo"
66
repository = "https://github.com/pplmx/husky-rs"
77
homepage = "https://github.com/pplmx/husky-rs"
88
readme = "README.md"
99
license = "MIT OR Apache-2.0"
1010
build = "build.rs"
11-
12-
[build-dependencies]
13-
thiserror = "^1.0"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add `husky-rs` to your `Cargo.toml`:
2020

2121
```toml
2222
[dependencies]
23-
husky-rs = "0.0.1"
23+
husky-rs = "0.1.0"
2424
```
2525

2626
## Usage

build.rs

+33-12
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,44 @@ use std::env;
22
use std::fs::{self, File};
33
use std::io::{self, BufRead, BufReader, Write};
44
use std::path::{Path, PathBuf};
5-
use thiserror::Error;
65

7-
#[derive(Error, Debug)]
6+
#[derive(Debug)]
87
enum HuskyError {
9-
#[error("Git directory not found in '{0}' or its parent directories")]
108
GitDirNotFound(String),
11-
#[error("IO error: {0}")]
12-
Io(#[from] io::Error),
13-
#[error("Environment variable error: {0}")]
14-
Env(#[from] env::VarError),
15-
#[error("User hook script is empty: '{0}'")]
9+
Io(io::Error),
10+
Env(env::VarError),
1611
EmptyUserHook(PathBuf),
1712
}
1813

14+
impl std::fmt::Display for HuskyError {
15+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16+
match self {
17+
HuskyError::GitDirNotFound(path) => write!(
18+
f,
19+
"Git directory not found in '{}' or its parent directories",
20+
path
21+
),
22+
HuskyError::Io(err) => write!(f, "IO error: {}", err),
23+
HuskyError::Env(err) => write!(f, "Environment variable error: {}", err),
24+
HuskyError::EmptyUserHook(path) => {
25+
write!(f, "User hook script is empty: '{}'", path.display())
26+
}
27+
}
28+
}
29+
}
30+
31+
impl From<io::Error> for HuskyError {
32+
fn from(err: io::Error) -> Self {
33+
HuskyError::Io(err)
34+
}
35+
}
36+
37+
impl From<env::VarError> for HuskyError {
38+
fn from(err: env::VarError) -> Self {
39+
HuskyError::Env(err)
40+
}
41+
}
42+
1943
type Result<T> = std::result::Result<T, HuskyError>;
2044

2145
const HUSKY_DIR: &str = ".husky";
@@ -116,10 +140,7 @@ fn read_file_lines(path: &Path) -> Result<Vec<String>> {
116140
let file = File::open(path)?;
117141
let reader = BufReader::new(file);
118142

119-
let mut lines: Vec<String> = reader
120-
.lines()
121-
.filter_map(|line| line.map_err(HuskyError::from).ok()) // Handle HuskyError
122-
.collect();
143+
let mut lines: Vec<String> = reader.lines().collect::<io::Result<_>>()?;
123144

124145
// Remove leading empty lines
125146
while lines.first().map_or(false, |line| line.trim().is_empty()) {

0 commit comments

Comments
 (0)