From c438c952b54ba187eb229f89ffcfeb3af528c441 Mon Sep 17 00:00:00 2001 From: Marco Radocchia Date: Wed, 3 Aug 2022 18:45:04 +0200 Subject: [PATCH] Added build.rs & Makefile --- .gitignore | 2 ++ CHANGELOG.md | 16 +++++++++++- Cargo.lock | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 11 ++++++++- Makefile | 37 +++++++++++++++++++++++++++ README.md | 58 ++++++++++++++++++++++++++----------------- TODO | 1 - build.rs | 35 ++++++++++++++++++++++++++ 8 files changed, 204 insertions(+), 26 deletions(-) create mode 100644 Makefile delete mode 100644 TODO create mode 100644 build.rs diff --git a/.gitignore b/.gitignore index ea8c4bf..ef5b4d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +/completions +/man diff --git a/CHANGELOG.md b/CHANGELOG.md index b3b4226..8c59da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog -# [0.1.0] - 2022-07-09 +## [0.2.0] - 2022-08-03 + +### Added + +- `directory` CLI option to specify output CSV file directory. +- `format` CLI option to specify output CSV filename format. +- `quiet` CLI option to mute standard output. +- `csv` CLI option to enable CSV file output at launch. +- Signal handler listening for `SIGUSR1` signals to toggle (*enable*/*disable*) + CSV file output at runtime (e.g. `pkill --signal=SIGUSR1 datalogger`). +- [build.rs](build.rs) build script to generate manpage & shell completions. +- [Makefile](Makefile) to compile/install/uninstall `datalogger` alongside + manpage & shell completions. + +## [0.1.0] - 2022-07-09 Initial release. diff --git a/Cargo.lock b/Cargo.lock index 60a0598..7c24c6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "atty" version = "0.2.14" @@ -61,6 +70,15 @@ dependencies = [ "textwrap", ] +[[package]] +name = "clap_complete" +version = "3.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ead064480dfc4880a10764488415a97fdd36a4cf1bb022d372f02e8faf8386e1" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "3.2.15" @@ -83,15 +101,30 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "clap_mangen" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "937efe4451c32be4ccb3e19549cbb1ea5cb85197f39b87a9662ca1d7b1765d1d" +dependencies = [ + "clap", + "roff", +] + [[package]] name = "datalogger" -version = "0.1.0" +version = "0.2.0" dependencies = [ "atty", "chrono", "clap", + "clap_complete", + "clap_mangen", "dht22_pi", "directories", + "lazy_static", + "qrcodegen", + "regex", "signal-hook", "termcolor", ] @@ -179,6 +212,12 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + [[package]] name = "num-integer" version = "0.1.45" @@ -243,6 +282,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "qrcodegen" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4339fc7a1021c9c1621d87f5e3505f2805c8c105420ba2f2a4df86814590c142" + [[package]] name = "quote" version = "1.0.20" @@ -272,6 +317,29 @@ dependencies = [ "thiserror", ] +[[package]] +name = "regex" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" + +[[package]] +name = "roff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316" + [[package]] name = "rppal" version = "0.13.1" diff --git a/Cargo.toml b/Cargo.toml index 280821f..9638496 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "datalogger" -version = "0.1.0" +version = "0.2.0" authors = ["Marco Radocchia -Humidity & Temperature datalogger for DHT22 sensor on Raspberry Pi. +Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi. ## Index - [Install](#install) - * [Master branch](#master-branch) - * [Latest release from crates.io](#latest-release-from-crates.io) + - [Git](#git) + - [Cargo](#cargo) + - [Master branch](#master-branch) + - [Latest release from crates.io](#latest-release-from-crates.io) - [Uninstall](#uninstall) - [Usage](#usage) - [Changelog](#changelog) @@ -30,14 +32,28 @@ on the system. In order to install such toolchain you can use `rusutp`: see https://www.rust-lang.org/tools/install for further installation instructions and notes. -### Master branch +### Git + +If you want to install `datalogger`, including **manpage** and shell +**completions** (Bash, Zsh, Fish), clone this repository and compile/install +using `make`: +```sh +git clone https://github.com/marcoradocchia/datalogger +cd datalogger +make +sudo make install +``` + +### Cargo + +#### Master branch To build and install from master branch run: ```sh cargo install --git https://github.com/marcoradocchia/datalogger --branch master ``` -### Latest release from crates.io +#### Latest release from crates.io To build and install the latest release from [crates.io](https://crates.io/crates/datalogger) run: @@ -45,31 +61,29 @@ To build and install the latest release from cargo install datalogger ``` -## Uninstall - -To uninstall run: -``` -cargo uninstall datalogger -``` - ## Usage ``` -datalogger 0.1.0 +datalogger 0.2.0 Marco Radocchia -Humidity & Temperature datalogger for DHT22 sensor on Raspberry Pi. +Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi. USAGE: - datalogger [OPTIONS] --pin [OUTPUT] - -ARGS: - Output CSV data file + datalogger [OPTIONS] --pin OPTIONS: - -h, --help Print help information - -i, --interval Interval in seconds between consecutive measures [default: 120] - -p, --pin GPIO pin for DHT22 data connection - -V, --version Print version information + --csv Dumps data to CSV file (can be swapped at runtime signalling + `datalogger` process with SIGUSR1) + -d, --directory Output CSV directory [default: ~] + -f, --format Output CSV filename format (see + https://docs.rs/chrono/latest/chrono/format/strftime/index.html + for valid specifiers) [default: %Y%m%d] + -h, --help Print help information + -i, --interval Interval in seconds between consecutive measures [default: 120] + -p, --pin GPIO pin for DHT22 data connection + -P, --pipe Print output as `` to stdout (for use in unix pipeline) + -q, --quiet Mute standard output + -V, --version Print version information ``` ## Changelog diff --git a/TODO b/TODO deleted file mode 100644 index a68bae5..0000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ -Set capabilities: `sudo setcap 'cap_sys_nice=eip' ./target/release/datalogger` diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..7fc2051 --- /dev/null +++ b/build.rs @@ -0,0 +1,35 @@ +use clap::CommandFactory; +use clap_complete::{generate_to, Shell::*}; +use clap_mangen::{self, Man}; +use std::env; + +// Include Args struct. +include!("src/args.rs"); + +fn main() { + // Generate man & completions directories. + let manifest_dir = + PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("unable to determine manifest dir")); + let man_dir = manifest_dir.join("man"); + let comp_dir = manifest_dir.join("completions"); + + fs::create_dir_all(&man_dir).expect("unable to create man directory"); + fs::create_dir_all(&comp_dir).expect("unable to create completions directory"); + + // Retrieve Args and set binary name. + let mut cmd = Args::command(); + cmd.set_bin_name("datalogger"); + + // Generate & write man page. + let mut buffer: Vec = Vec::new(); + Man::new(cmd.clone()) + .render(&mut buffer) + .expect("unable to generate man page"); + fs::write(man_dir.join("datalogger.1"), buffer).expect("unable to write man page"); + + // Generate shell completions. + for shell in [Bash, Fish, Zsh] { + generate_to(shell, &mut cmd, "datalogger", &comp_dir) + .expect("unable to generate completions"); + } +}