Skip to content

Commit 2cb79b0

Browse files
author
qtfkwk
committed
0.3.0
1 parent e9153b8 commit 2cb79b0

File tree

9 files changed

+363
-333
lines changed

9 files changed

+363
-333
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
* 0.1.0 (2020-02-03): Initial release
4+
* 0.2.1 (2020-02-09): Produce `.sha256` files compatible w/ `sha256sum -c`
5+
* 0.2.2 (2020-11-18): Update sha2 crate version
6+
* 0.3.0 (2023-01-07): Modernize
7+

Cargo.toml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
[package]
22
name = "fhc"
3-
description = "file hash checker (SHA256)"
3+
version = "0.3.0"
4+
edition = "2021"
5+
description = "File hash checker (SHA256)"
6+
repository = "https://github.com/qtfkwk/fhc"
7+
license = "MIT"
48
keywords = ["sha256sum", "sha256", "integrity"]
59
categories = ["command-line-utilities"]
6-
version = "0.2.2"
7-
license = "MIT"
8-
repository = "https://github.com/qtfkwk/fhc"
9-
authors = ["qtfkwk <qtfkwk+fhc@gmail.com>"]
10-
edition = "2018"
11-
include = [
12-
"Cargo.toml",
13-
"src",
14-
]
1510

1611
[dependencies]
17-
sha2 = "0.8.1"
12+
anyhow = "1.0.79"
13+
clap = { version = "4.4.13", features = ["derive", "wrap_help"] }
14+
sha2 = "0.10.8"

LICENSE.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

Makefile.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# build
2+
3+
* clippy
4+
* `README.md`
5+
* test
6+
7+
```
8+
cargo build --release
9+
```
10+
11+
# `README.md`
12+
13+
* `t/README.md`
14+
* `Cargo.toml`
15+
* `CHANGELOG.md`
16+
* `src/**/*.rs`
17+
18+
```
19+
cargo build --release
20+
kapow {0} >{target}
21+
```
22+
23+
# clippy
24+
25+
```
26+
cargo clippy -- -D clippy::all
27+
```
28+
29+
# test
30+
31+
```
32+
cargo test -- --nocapture --test-threads=1
33+
```
34+
35+
# check
36+
37+
```
38+
cargo outdated --exit-code 1
39+
cargo audit
40+
```
41+
42+
# update
43+
44+
```
45+
cargo upgrade --incompatible
46+
cargo update
47+
```
48+
49+
# install
50+
51+
* `README.md`
52+
53+
```
54+
cargo install --path .
55+
```
56+
57+
# uninstall
58+
59+
```
60+
cargo uninstall $(toml get -r Cargo.toml package.name)
61+
```
62+
63+
# install-deps
64+
65+
```
66+
cargo install cargo-audit cargo-edit cargo-outdated cocomo dtg kapow tokei toml-cli
67+
```
68+
69+
# scaffold
70+
71+
```bash -eo pipefail
72+
if ! toml get -r Cargo.toml package.description >/dev/null; then
73+
toml set Cargo.toml package.description "Insert a description here" >Cargo.toml.new
74+
mv Cargo.toml.new Cargo.toml
75+
echo Edit package description in Cargo.toml, then rerun \`mkrs scaffold\`.
76+
exit 0
77+
fi
78+
mkdir -p t
79+
if [ ! -e t/README.md ]; then
80+
NAME=$(toml get -r Cargo.toml package.name)
81+
ABOUT=$(toml get -r Cargo.toml package.description)
82+
cat <<EOF >t/README.md
83+
# About
84+
85+
$ABOUT
86+
87+
# Usage
88+
89+
~~~text
90+
\$ $NAME -V
91+
!run:../target/release/$NAME -V 2>&1
92+
~~~
93+
94+
~~~text
95+
\$ $NAME -h
96+
!run:../target/release/$NAME -h 2>&1
97+
~~~
98+
99+
!inc:../CHANGELOG.md
100+
101+
EOF
102+
fi
103+
if [ ! -e CHANGELOG.md ]; then
104+
VERSION=$(toml get -r Cargo.toml package.version)
105+
TODAY=$(dtg -n %Y-%m-%d)
106+
cat <<EOF >CHANGELOG.md
107+
# Changelog
108+
109+
* $VERSION ($TODAY): Initial release
110+
111+
EOF
112+
fi
113+
```
114+
115+
# clean
116+
117+
```
118+
cargo clean
119+
```
120+
121+
# cocomo
122+
123+
```bash -eo pipefail
124+
tokei; echo
125+
cocomo -o sloccount
126+
cocomo
127+
```
128+
129+
# full
130+
131+
* update
132+
* check
133+
* build
134+
* install
135+

README.md

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# About
22

3-
File hash checker ("fhc") represents a minimal solution meeting the following
3+
File hash checker represents a minimal solution meeting the following
44
requirements:
55

6-
* Calculate the SHA256 hash of one or more files in parallel
7-
* Minimal external dependencies:
8-
* [sha2](https://crates.io/crates/sha2)
6+
* Calculate the SHA256 hashes of one or more files in sequence or parallel
7+
(threading or messaging)
8+
* Minimal external dependencies: [`sha2`], [`anyhow`], [`clap`]
99
* Provide a library function than returns the SHA256 hash as a hex string for a
1010
string path
1111
* Provide a CLI utiility:
@@ -15,36 +15,26 @@ requirements:
1515
* Compare the current SHA256 hash to an adjacent `.sha256` file (if it
1616
exists)
1717

18-
# Installation
19-
20-
## User
21-
22-
```bash
23-
cargo install fhc
24-
```
25-
26-
## Developer
27-
28-
```bash
29-
git clone https://github.com/qtfkwk/fhc.git
30-
cd fhc
31-
cargo install --path=.
32-
```
18+
[anyhow]: https://crates.io/crates/anyhow
19+
[clap]: https://crates.io/crates/clap
20+
[sha2]: https://crates.io/crates/sha2
3321

3422
# Usage
3523

3624
```
3725
$ fhc -h
38-
# fhc (file hash checker), 0.2.2, 2020-11-18
26+
File hash checker (SHA256)
27+
28+
Usage: fhc [OPTIONS] [FILES]...
3929
40-
Usage: `fhc [-h|--help] [--version] [-p|--process OPTION] [file]`
30+
Arguments:
31+
[FILES]... File(s)
4132
42-
Option/argument | Description
43-
----------------------|--------------------------------------------------
44-
`-h|--help` | show help
45-
`--version` | show version/date
46-
`-p|--process OPTION` | process option: messaging*, threading, sequential
47-
`file` | one or more file paths
33+
Options:
34+
-p, --process <PROCESS> Process option [default: messaging] [possible values:
35+
sequential, threading, messaging]
36+
-h, --help Print help
37+
-V, --version Print version
4838
```
4939

5040
# Example
@@ -55,14 +45,10 @@ Option/argument | Description
5545
`.sha256` files to re-calculate the SHA256 hash for each file and report `OK`
5646
if the hashes match and `FAILED` if the hashes do not match.
5747

58-
# Tests
59-
60-
The [test.log](test.log) file saves the output of
61-
`cargo test 2>&1 |tee test.log` at each commit.
62-
6348
# Changelog
6449

65-
* 0.1.0 (2020-02-03): initial public release
66-
* 0.2.1 (2020-02-09): produce `.sha256` files compatible w/ `sha256sum -c`
67-
* 0.2.2 (2020-11-18): update sha2 crate version
50+
* 0.1.0 (2020-02-03): Initial release
51+
* 0.2.1 (2020-02-09): Produce `.sha256` files compatible w/ `sha256sum -c`
52+
* 0.2.2 (2020-11-18): Update sha2 crate version
53+
* 0.3.0 (2023-01-07): Modernize
6854

src/bin/fhc.rs

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,89 @@
1-
/*
1+
use anyhow::Result;
2+
use clap::Parser;
3+
use fhc::*;
4+
use std::path::PathBuf;
25

3-
Copyright 2020 qtfkwk <qtfkwk+fhc@gmail.com>
6+
#[derive(Clone, Debug, clap::ValueEnum)]
7+
enum ProcessOption {
8+
Sequential,
9+
Threading,
10+
Messaging,
11+
}
12+
13+
use ProcessOption::*;
414

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9-
of the Software, and to permit persons to whom the Software is furnished to do
10-
so, subject to the following conditions:
15+
#[derive(Parser)]
16+
#[command(about, version, max_term_width = 80)]
17+
struct Cli {
18+
/// Process option
19+
#[arg(short, long, default_value = "messaging")]
20+
process: ProcessOption,
1121

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
22+
/// File(s)
23+
files: Vec<PathBuf>,
24+
}
1425

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
26+
fn main() -> Result<()> {
27+
let cli = Cli::parse();
2228

23-
*/
29+
let process = if cli.files.len() == 1 {
30+
Sequential
31+
} else {
32+
cli.process.clone()
33+
};
2434

25-
use fhc::cli;
35+
match process {
36+
Sequential => {
37+
for file in &cli.files {
38+
match process_file(file) {
39+
Ok(r) => println!("{}", r),
40+
Err(e) => {
41+
eprintln!("ERROR: {}", e);
42+
}
43+
}
44+
}
45+
}
46+
Threading => {
47+
let mut handles = vec![];
48+
for file in cli.files.iter().cloned() {
49+
handles.push(std::thread::spawn(move || process_file(file)));
50+
}
51+
for handle in handles {
52+
match handle.join() {
53+
Ok(t) => match t {
54+
Ok(r) => println!("{}", r),
55+
Err(e) => {
56+
eprintln!("ERROR: {}", e);
57+
}
58+
},
59+
Err(e) => {
60+
eprintln!("ERROR: {:?}", e);
61+
}
62+
}
63+
}
64+
}
65+
Messaging => {
66+
let mut rxs = vec![];
67+
for file in cli.files.iter().cloned() {
68+
let (tx, rx) = std::sync::mpsc::channel();
69+
rxs.push(rx);
70+
std::thread::spawn(move || tx.send(process_file(file)).unwrap());
71+
}
72+
for rx in rxs {
73+
match rx.recv() {
74+
Ok(t) => match t {
75+
Ok(r) => println!("{}", r),
76+
Err(e) => {
77+
eprintln!("ERROR: {}", e);
78+
}
79+
},
80+
Err(e) => {
81+
eprintln!("ERROR: {:?}", e);
82+
}
83+
}
84+
}
85+
}
86+
}
2687

27-
fn main() {
28-
cli().unwrap();
88+
Ok(())
2989
}
30-

0 commit comments

Comments
 (0)