From 9b4ef82b10da95908564e807817c5bed7b8b45f0 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 9 Feb 2024 18:38:12 +0100 Subject: [PATCH 01/14] fix ci --- .gitea/workflows/cargo.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/cargo.yaml b/.gitea/workflows/cargo.yaml index 017d21c..b4a75df 100644 --- a/.gitea/workflows/cargo.yaml +++ b/.gitea/workflows/cargo.yaml @@ -16,7 +16,7 @@ jobs: - name: get repo uses: actions/checkout@v4 - name: install rust - uses: dtolnay/rust-toolchain@stable + uses: https://github.com/dtolnay/rust-toolchain@stable - name: install additional rust things run: rustup component add rustfmt - name: config custom registry @@ -37,7 +37,7 @@ jobs: - name: cargo test run: cargo test --all-features --all-targets - name: commit back to repository - uses: stefanzweifel/git-auto-commit-action@v5 + uses: https://github.com/stefanzweifel/git-auto-commit-action@v5 with: # Optional. Commit message for the created commit. # Defaults to "Apply automatic changes" From 138ad5d9698f999547f92e991a20916720d4edf6 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 16 Feb 2024 16:11:46 +0100 Subject: [PATCH 02/14] ci stuff --- .gitea/workflows/cargo.yaml | 8 ++++---- .github/workflows/cargo.yaml | 8 ++++---- scripts/release.sh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/cargo.yaml b/.gitea/workflows/cargo.yaml index b4a75df..5d9a9e1 100644 --- a/.gitea/workflows/cargo.yaml +++ b/.gitea/workflows/cargo.yaml @@ -28,10 +28,10 @@ jobs: echo '[registries.cscherr]' >> ~/.cargo/config.toml echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml cat ~/.cargo/config.toml - - name: cargo check - run: cargo check --all-features --all-targets - - name: cargo fix - run: cargo fix --all-features --all-targets + - name: cargo clippy check + run: cargo clippy --all-features --all-targets + - name: cargo clippy fix + run: cargo clippy --fix --all-features --all-targets - name: cargo fmt run: cargo fmt --all - name: cargo test diff --git a/.github/workflows/cargo.yaml b/.github/workflows/cargo.yaml index ad223f1..0377430 100644 --- a/.github/workflows/cargo.yaml +++ b/.github/workflows/cargo.yaml @@ -29,10 +29,10 @@ jobs: echo '[registries.cscherr]' >> ~/.cargo/config.toml echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml cat ~/.cargo/config.toml - - name: cargo check - run: cargo check --all-features --all-targets - - name: cargo fix - run: cargo fix --all-features --all-targets + - name: cargo clippy check + run: cargo clippy --all-features --all-targets + - name: cargo clippy fix + run: cargo clippy --fix --all-features --all-targets - name: cargo fmt run: cargo fmt --all - name: cargo test diff --git a/scripts/release.sh b/scripts/release.sh index 943ad51..275ed55 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -7,7 +7,7 @@ BODY=" $(git log $(git describe --tags --abbrev=0)..HEAD --pretty="- %s" --oneline --decorate) " USER=PlexSheep -git tag "v$NEW_VERSION-test" || echo "could not tag" +git tag "v$NEW_VERSION" || echo "could not tag" curl -X 'POST' \ 'https://git.cscherr.de/api/v1/repos/PlexSheep/'$REPO'/releases' \ -H 'accept: application/json' \ From 04f683807f2ecd8cdfc6377e2137bd1b268af8f6 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 16 Feb 2024 16:35:09 +0100 Subject: [PATCH 03/14] ci add clippy rustup --- .gitea/workflows/cargo.yaml | 4 +++- .github/workflows/cargo.yaml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/cargo.yaml b/.gitea/workflows/cargo.yaml index 5d9a9e1..f35cb90 100644 --- a/.gitea/workflows/cargo.yaml +++ b/.gitea/workflows/cargo.yaml @@ -18,7 +18,9 @@ jobs: - name: install rust uses: https://github.com/dtolnay/rust-toolchain@stable - name: install additional rust things - run: rustup component add rustfmt + run: | + rustup component add rustfmt + rustup component add clippy - name: config custom registry run: | mkdir -p ~/.cargo/ diff --git a/.github/workflows/cargo.yaml b/.github/workflows/cargo.yaml index 0377430..ea06297 100644 --- a/.github/workflows/cargo.yaml +++ b/.github/workflows/cargo.yaml @@ -19,7 +19,9 @@ jobs: - name: install rust uses: dtolnay/rust-toolchain@stable - name: install additional rust things - run: rustup component add rustfmt + run: | + rustup component add rustfmt + rustup component add clippy - name: config custom registry run: | mkdir -p ~/.cargo/ From 8091e9ce1e642c3bb2c0c3c32fb6171366bc3021 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 16 Feb 2024 15:39:04 +0000 Subject: [PATCH 04/14] automatic cargo CI changes --- src/dumper.rs | 10 +++++----- src/main.rs | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/dumper.rs b/src/dumper.rs index b8ec30d..d1c65df 100644 --- a/src/dumper.rs +++ b/src/dumper.rs @@ -9,7 +9,7 @@ use libpt::log::{debug, error, trace, warn}; pub const BYTES_PER_LINE: usize = 16; pub const LINE_SEP_HORIZ: char = '─'; pub const LINE_SEP_VERT: char = '│'; -pub const CHAR_BORDER: &'static str = "|"; +pub const CHAR_BORDER: &str = "|"; pub trait DataSource: Read { fn skip(&mut self, length: usize) -> std::io::Result<()>; @@ -93,16 +93,16 @@ impl Hedu { self.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", self.data_idx); if self.len != 0 { for i in 0..self.len { - if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { + if i % BYTES_PER_LINE == BYTES_PER_LINE / 2 { self.display_buf += " "; } self.display_buf += &format!("{:02X} ", self.buf[self.alt_buf][i]); } if self.len == BYTES_PER_LINE / 2 { - self.display_buf += " " + self.display_buf += " "; } for i in 0..(BYTES_PER_LINE - self.len) { - if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 { + if i % BYTES_PER_LINE == BYTES_PER_LINE / 2 { self.display_buf += " "; } self.display_buf += " "; @@ -237,7 +237,7 @@ impl Hedu { /// interpret characters for the --chars option fn mask_chars(c: char) -> char { if c.is_ascii_graphic() { - return c; + c } else if c == '\n' { return '↩'; } else if c == ' ' { diff --git a/src/main.rs b/src/main.rs index baa269b..aa0be7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,13 +5,13 @@ use std::{fs::File, io::IsTerminal, path::PathBuf}; -use libpt::log::*; +use libpt::log::{error, trace, warn, Level, Logger}; use clap::Parser; use clap_verbosity_flag::{InfoLevel, Verbosity}; mod dumper; -use dumper::*; +use dumper::{DataSource, Hedu}; #[derive(Debug, Clone, Parser)] #[command( @@ -63,7 +63,7 @@ pub struct Cli { fn main() { let mut cli = cli_parse(); let mut sources: Vec> = Vec::new(); - if cli.data_source.len() > 0 && cli.data_source[0] != "-" { + if !cli.data_source.is_empty() && cli.data_source[0] != "-" { for data_source in &cli.data_source { let data_source: PathBuf = PathBuf::from(data_source); if data_source.is_dir() { @@ -89,7 +89,7 @@ fn main() { } // just for the little header cli.data_source = Vec::new(); - cli.data_source.push(format!("stdin")); + cli.data_source.push("stdin".to_string()); sources.push(Box::new(stdin)); } for (i, source) in sources.iter_mut().enumerate() { @@ -105,7 +105,7 @@ fn main() { } } match config.dump(&mut **source) { - Ok(_) => (), + Ok(()) => (), Err(err) => { error!("Could not dump data of file: {err}"); std::process::exit(3); @@ -135,5 +135,5 @@ fn cli_parse() -> Cli { // less verbose version Logger::init_mini(Some(ll)).expect("could not initialize Logger"); } - return cli; + cli } From 21731687f427f2e4ccc8d37aab494f491a91e3c0 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 12 May 2024 17:27:31 +0200 Subject: [PATCH 05/14] ci add cargo test of docs --- .gitea/workflows/cargo.yaml | 6 +++--- .github/workflows/cargo.yaml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/cargo.yaml b/.gitea/workflows/cargo.yaml index f35cb90..6b9afbb 100644 --- a/.gitea/workflows/cargo.yaml +++ b/.gitea/workflows/cargo.yaml @@ -31,13 +31,13 @@ jobs: echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml cat ~/.cargo/config.toml - name: cargo clippy check - run: cargo clippy --all-features --all-targets + run: cargo clippy --all-features --all-targets --workspace - name: cargo clippy fix - run: cargo clippy --fix --all-features --all-targets + run: cargo clippy --fix --all-features --all-targets --workspace - name: cargo fmt run: cargo fmt --all - name: cargo test - run: cargo test --all-features --all-targets + run: cargo test --all-features --all-targets --workspace && cargo test --all-features --workspace --doc - name: commit back to repository uses: https://github.com/stefanzweifel/git-auto-commit-action@v5 with: diff --git a/.github/workflows/cargo.yaml b/.github/workflows/cargo.yaml index ea06297..d2c9936 100644 --- a/.github/workflows/cargo.yaml +++ b/.github/workflows/cargo.yaml @@ -32,13 +32,13 @@ jobs: echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml cat ~/.cargo/config.toml - name: cargo clippy check - run: cargo clippy --all-features --all-targets + run: cargo clippy --all-features --all-targets --workspace - name: cargo clippy fix - run: cargo clippy --fix --all-features --all-targets + run: cargo clippy --fix --all-features --all-targets --workspace - name: cargo fmt run: cargo fmt --all - name: cargo test - run: cargo test --all-features --all-targets + run: cargo test --all-features --all-targets --workspace && cargo test --all-features --workspace --doc - name: commit back to repository uses: stefanzweifel/git-auto-commit-action@v5 with: From f6c9c3c820fe5c5fbb50472537a4c21b75a12bb0 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 23 May 2024 14:41:27 +0200 Subject: [PATCH 06/14] chore: update libpt and adjust to breaking changes #5 --- Cargo.toml | 2 +- src/main.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b119d7..b6189ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://git.cscherr.de/PlexSheep/hedu" keywords = ["hexdumper"] [dependencies] -libpt = { version = "0.3.11", features = ["log", "bintols"] } +libpt = { version = "0.5.1", features = ["log", "bintols"] } clap = { version = "4.4.4", features = ["derive", "help"] } clap-num = { version = "1.0.2" } clap-verbosity-flag = { version = "2.0.1" } diff --git a/src/main.rs b/src/main.rs index aa0be7c..0d9bb64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,10 +130,10 @@ fn cli_parse() -> Cli { } }; if cli.meta { - Logger::init(None, Some(ll), false).expect("could not initialize Logger"); + let _ = Logger::builder().max_level(ll).build(); } else { // less verbose version - Logger::init_mini(Some(ll)).expect("could not initialize Logger"); + let _ = Logger::builder().build(); } cli } From fb145a7ff43eb3b6471003c065e6f324da0caa3b Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 23 May 2024 14:51:56 +0200 Subject: [PATCH 07/14] fix!: less dependencies and simpler cli #6 --- Cargo.toml | 4 +--- src/main.rs | 21 +++++++-------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b6189ba..48ebb7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,6 @@ repository = "https://git.cscherr.de/PlexSheep/hedu" keywords = ["hexdumper"] [dependencies] -libpt = { version = "0.5.1", features = ["log", "bintols"] } +libpt = { version = "0.5.1", features = ["bintols"], default-features = false } clap = { version = "4.4.4", features = ["derive", "help"] } -clap-num = { version = "1.0.2" } -clap-verbosity-flag = { version = "2.0.1" } anyhow = "1.0.79" diff --git a/src/main.rs b/src/main.rs index 0d9bb64..06bdb5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ use std::{fs::File, io::IsTerminal, path::PathBuf}; use libpt::log::{error, trace, warn, Level, Logger}; use clap::Parser; -use clap_verbosity_flag::{InfoLevel, Verbosity}; mod dumper; use dumper::{DataSource, Hedu}; @@ -29,10 +28,9 @@ Author: {author-with-newline} )] /// Hexdumper written in Rust pub struct Cli { - // clap_verbosity_flag seems to make this a global option implicitly - /// set a verbosity, multiple allowed (f.e. -vvv) - #[command(flatten)] - pub verbose: Verbosity, + /// show more details + #[arg(short, long)] + pub verbose: bool, /// show additional logging meta data #[arg(long)] @@ -119,15 +117,10 @@ fn main() { fn cli_parse() -> Cli { let cli = Cli::parse(); - let ll: Level = match cli.verbose.log_level().unwrap().as_str() { - "TRACE" => Level::TRACE, - "DEBUG" => Level::DEBUG, - "INFO" => Level::INFO, - "WARN" => Level::WARN, - "ERROR" => Level::ERROR, - _ => { - unreachable!(); - } + let ll: Level = if cli.verbose { + Level::INFO + } else { + Level::DEBUG }; if cli.meta { let _ = Logger::builder().max_level(ll).build(); From 7929b0af2fcd8ede5f193714077811d5f7c1e4f4 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 23 May 2024 14:55:03 +0200 Subject: [PATCH 08/14] docs(help): dirs cannot be dumped #4 --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 06bdb5c..fdd4db9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,6 +55,8 @@ pub struct Cli { /// a data source, probably a file. /// /// If left empty or set as "-", the program will read from stdin. + /// + /// Directories cannot be dumped. pub data_source: Vec, } From 7ee73c4f64f7aba7daa6baab701a01daa66c2686 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 23 May 2024 14:56:37 +0200 Subject: [PATCH 09/14] chore: fix regression from #5, don't show time if not in meta logging mode --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fdd4db9..3d4acef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -128,7 +128,7 @@ fn cli_parse() -> Cli { let _ = Logger::builder().max_level(ll).build(); } else { // less verbose version - let _ = Logger::builder().build(); + let _ = Logger::builder().show_time(false).build(); } cli } From 18008e9c41fe4141a824885c7c58a53563a08fab Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 23 May 2024 14:57:17 +0200 Subject: [PATCH 10/14] chore: add log to libpt features --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 48ebb7d..8244a22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,6 @@ repository = "https://git.cscherr.de/PlexSheep/hedu" keywords = ["hexdumper"] [dependencies] -libpt = { version = "0.5.1", features = ["bintols"], default-features = false } +libpt = { version = "0.5.1", features = ["bintols", "log"], default-features = false } clap = { version = "4.4.4", features = ["derive", "help"] } anyhow = "1.0.79" From 256b362f39a4dd933b6b3af606e8190d25b52d58 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 24 May 2024 09:18:51 +0200 Subject: [PATCH 11/14] fix(cli): accept "-" for stdin marker at any position #2 --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3d4acef..b2bb915 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,11 +63,11 @@ pub struct Cli { fn main() { let mut cli = cli_parse(); let mut sources: Vec> = Vec::new(); - if !cli.data_source.is_empty() && cli.data_source[0] != "-" { + if !cli.data_source.is_empty() && !cli.data_source.contains(&"-".to_string()) { for data_source in &cli.data_source { let data_source: PathBuf = PathBuf::from(data_source); if data_source.is_dir() { - warn!("Not a file {:?}, skipping", data_source); + warn!("'{:?}' is a directory and cannot be dumped, skipping", data_source); // std::process::exit(1); continue; } From 3cb2f2a77829f2f837a18da7d78e54912362ddb6 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 24 May 2024 09:25:25 +0200 Subject: [PATCH 12/14] chore: bump to v0.2.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8244a22..10b1299 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hedu" -version = "0.1.1" +version = "0.2.0" edition = "2021" publish = true authors = ["Christoph J. Scherr "] From 3d9ddac2376b34b7e650d2f719526e58fe4f0322 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 24 May 2024 09:29:32 +0200 Subject: [PATCH 13/14] chore: remove doctest from CI (this is a binary) --- .gitea/workflows/cargo.yaml | 2 +- .github/workflows/cargo.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/cargo.yaml b/.gitea/workflows/cargo.yaml index 6b9afbb..b755c81 100644 --- a/.gitea/workflows/cargo.yaml +++ b/.gitea/workflows/cargo.yaml @@ -37,7 +37,7 @@ jobs: - name: cargo fmt run: cargo fmt --all - name: cargo test - run: cargo test --all-features --all-targets --workspace && cargo test --all-features --workspace --doc + run: cargo test --all-features --all-targets --workspace - name: commit back to repository uses: https://github.com/stefanzweifel/git-auto-commit-action@v5 with: diff --git a/.github/workflows/cargo.yaml b/.github/workflows/cargo.yaml index d2c9936..29abfde 100644 --- a/.github/workflows/cargo.yaml +++ b/.github/workflows/cargo.yaml @@ -38,7 +38,7 @@ jobs: - name: cargo fmt run: cargo fmt --all - name: cargo test - run: cargo test --all-features --all-targets --workspace && cargo test --all-features --workspace --doc + run: cargo test --all-features --all-targets --workspace - name: commit back to repository uses: stefanzweifel/git-auto-commit-action@v5 with: From d51c4dde90e9d36f918fff8f3ff6a101a51ab0d8 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 24 May 2024 07:30:51 +0000 Subject: [PATCH 14/14] automatic cargo CI changes --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index b2bb915..b2efafc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,7 +67,10 @@ fn main() { for data_source in &cli.data_source { let data_source: PathBuf = PathBuf::from(data_source); if data_source.is_dir() { - warn!("'{:?}' is a directory and cannot be dumped, skipping", data_source); + warn!( + "'{:?}' is a directory and cannot be dumped, skipping", + data_source + ); // std::process::exit(1); continue; }