Skip to content

Commit c438c95

Browse files
Added build.rs & Makefile
1 parent a1b5a25 commit c438c95

File tree

8 files changed

+204
-26
lines changed

8 files changed

+204
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/target
2+
/completions
3+
/man

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3-
# [0.1.0] - 2022-07-09
3+
## [0.2.0] - 2022-08-03
4+
5+
### Added
6+
7+
- `directory` CLI option to specify output CSV file directory.
8+
- `format` CLI option to specify output CSV filename format.
9+
- `quiet` CLI option to mute standard output.
10+
- `csv` CLI option to enable CSV file output at launch.
11+
- Signal handler listening for `SIGUSR1` signals to toggle (*enable*/*disable*)
12+
CSV file output at runtime (e.g. `pkill --signal=SIGUSR1 datalogger`).
13+
- [build.rs](build.rs) build script to generate manpage & shell completions.
14+
- [Makefile](Makefile) to compile/install/uninstall `datalogger` alongside
15+
manpage & shell completions.
16+
17+
## [0.1.0] - 2022-07-09
418

519
Initial release.

Cargo.lock

Lines changed: 69 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "datalogger"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Marco Radocchia <[email protected]"]
55
edition = "2021"
66
rust-version = "1.61.0"
@@ -22,6 +22,15 @@ directories = "4.0.1"
2222
termcolor = "1.1.3"
2323
atty = "0.2.14"
2424

25+
[build-dependencies]
26+
clap = { version = "3.2.16", features = ["derive"] }
27+
clap_mangen = "0.1.10"
28+
clap_complete = "3.2.3"
29+
qrcodegen = "1.8.0"
30+
lazy_static = "1.4.0"
31+
regex = "1.6.0"
32+
directories = "4.0.1"
33+
2534
[profile.release]
2635
lto = true # link-time-optimization
2736
strip = true # strip symbols from binary

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Paths.
2+
PREFIX = /usr/local
3+
MANPREFIX = ${PREFIX}/share/man
4+
COMPPREFIX = /usr/share
5+
6+
all:
7+
# Compile & generate manpage and completions for Bash, Fish, Zsh.
8+
cargo build --release
9+
10+
install:
11+
# Install binary.
12+
mkdir -p ${DESTDIR}${PREFIX}/bin
13+
setcap 'cap_sys_nice=eip' target/release/datalogger
14+
install -Dm 755 target/release/datalogger -t "${DESTDIR}${PREFIX}/bin"
15+
# Install manpage.
16+
mkdir -p ${DESTDIR}${MANPREFIX}/man1
17+
install -Dm 644 man/datalogger.1 -t "${DESTDIR}${MANPREFIX}/man1"
18+
# Install shell completions.
19+
mkdir -p ${COMPPREFIX}/bash-completion/completions\
20+
${COMPPREFIX}/zsh/site_functions\
21+
${COMPPREFIX}/fish/vendor_completions.d
22+
install -Dm 644 completions/datalogger.bash -t "${COMPPREFIX}/bash-completion/completions"
23+
install -Dm 644 completions/_datalogger -t "${COMPPREFIX}/zsh/site-functions"
24+
install -Dm 644 completions/datalogger.fish -t "${COMPPREFIX}/fish/vendor_completions.d"
25+
26+
uninstall:
27+
rm -f ${DESTDIR}${PREFIX}/bin/datalogger\
28+
${DESTDIR}${MANPREFIX}/man1/datalogger.1\
29+
${COMPPREFIX}/bash-completion/completions/datalogger.bash\
30+
${COMPPREFIX}/zsh/site-functions/_datalogger\
31+
${COMPPREFIX}/fish/vendor_completions.d/datalogger.fish
32+
33+
clean:
34+
cargo clean
35+
rm -rf completions man
36+
37+
.PHONY: all install uninstall clean

README.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
<!-- ![Crates.io version](https://img.shields.io/crates/v/datalogger?logo=rust&color=%23d8a657) -->
1212
</div>
1313

14-
Humidity & Temperature datalogger for DHT22 sensor on Raspberry Pi.
14+
Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi.
1515

1616
## Index
1717

1818
- [Install](#install)
19-
* [Master branch](#master-branch)
20-
* [Latest release from crates.io](#latest-release-from-crates.io)
19+
- [Git](#git)
20+
- [Cargo](#cargo)
21+
- [Master branch](#master-branch)
22+
- [Latest release from crates.io](#latest-release-from-crates.io)
2123
- [Uninstall](#uninstall)
2224
- [Usage](#usage)
2325
- [Changelog](#changelog)
@@ -30,46 +32,58 @@ on the system. In order to install such toolchain you can use `rusutp`: see
3032
https://www.rust-lang.org/tools/install for further installation
3133
instructions and notes.
3234

33-
### Master branch
35+
### Git
36+
37+
If you want to install `datalogger`, including **manpage** and shell
38+
**completions** (Bash, Zsh, Fish), clone this repository and compile/install
39+
using `make`:
40+
```sh
41+
git clone https://github.com/marcoradocchia/datalogger
42+
cd datalogger
43+
make
44+
sudo make install
45+
```
46+
47+
### Cargo
48+
49+
#### Master branch
3450

3551
To build and install from master branch run:
3652
```sh
3753
cargo install --git https://github.com/marcoradocchia/datalogger --branch master
3854
```
3955

40-
### Latest release from crates.io
56+
#### Latest release from crates.io
4157

4258
To build and install the latest release from
4359
[crates.io](https://crates.io/crates/datalogger) run:
4460
```
4561
cargo install datalogger
4662
```
4763

48-
## Uninstall
49-
50-
To uninstall run:
51-
```
52-
cargo uninstall datalogger
53-
```
54-
5564
## Usage
5665

5766
```
58-
datalogger 0.1.0
67+
datalogger 0.2.0
5968
Marco Radocchia <[email protected]>
60-
Humidity & Temperature datalogger for DHT22 sensor on Raspberry Pi.
69+
Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi.
6170
6271
USAGE:
63-
datalogger [OPTIONS] --pin <PIN> [OUTPUT]
64-
65-
ARGS:
66-
<OUTPUT> Output CSV data file
72+
datalogger [OPTIONS] --pin <PIN>
6773
6874
OPTIONS:
69-
-h, --help Print help information
70-
-i, --interval <INTERVAL> Interval in seconds between consecutive measures [default: 120]
71-
-p, --pin <PIN> GPIO pin for DHT22 data connection
72-
-V, --version Print version information
75+
--csv Dumps data to CSV file (can be swapped at runtime signalling
76+
`datalogger` process with SIGUSR1)
77+
-d, --directory <DIRECTORY> Output CSV directory [default: ~]
78+
-f, --format <FORMAT> Output CSV filename format (see
79+
https://docs.rs/chrono/latest/chrono/format/strftime/index.html
80+
for valid specifiers) [default: %Y%m%d]
81+
-h, --help Print help information
82+
-i, --interval <INTERVAL> Interval in seconds between consecutive measures [default: 120]
83+
-p, --pin <PIN> GPIO pin for DHT22 data connection
84+
-P, --pipe Print output as `<hum,temp>` to stdout (for use in unix pipeline)
85+
-q, --quiet Mute standard output
86+
-V, --version Print version information
7387
```
7488

7589
## Changelog

TODO

Lines changed: 0 additions & 1 deletion
This file was deleted.

build.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use clap::CommandFactory;
2+
use clap_complete::{generate_to, Shell::*};
3+
use clap_mangen::{self, Man};
4+
use std::env;
5+
6+
// Include Args struct.
7+
include!("src/args.rs");
8+
9+
fn main() {
10+
// Generate man & completions directories.
11+
let manifest_dir =
12+
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("unable to determine manifest dir"));
13+
let man_dir = manifest_dir.join("man");
14+
let comp_dir = manifest_dir.join("completions");
15+
16+
fs::create_dir_all(&man_dir).expect("unable to create man directory");
17+
fs::create_dir_all(&comp_dir).expect("unable to create completions directory");
18+
19+
// Retrieve Args and set binary name.
20+
let mut cmd = Args::command();
21+
cmd.set_bin_name("datalogger");
22+
23+
// Generate & write man page.
24+
let mut buffer: Vec<u8> = Vec::new();
25+
Man::new(cmd.clone())
26+
.render(&mut buffer)
27+
.expect("unable to generate man page");
28+
fs::write(man_dir.join("datalogger.1"), buffer).expect("unable to write man page");
29+
30+
// Generate shell completions.
31+
for shell in [Bash, Fish, Zsh] {
32+
generate_to(shell, &mut cmd, "datalogger", &comp_dir)
33+
.expect("unable to generate completions");
34+
}
35+
}

0 commit comments

Comments
 (0)