Compare commits

..

No commits in common. "master" and "v0.1.1" have entirely different histories.

9 changed files with 99 additions and 121 deletions

View File

@ -0,0 +1,44 @@
name: cargo devel CI
on:
push:
branches:
- '**'
# - '!master'
jobs:
format:
name: cargo CI
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- name: get repo
uses: actions/checkout@v4
- name: install rust
uses: dtolnay/rust-toolchain@stable
- name: install additional rust things
run: rustup component add rustfmt
- name: config custom registry
run: |
mkdir -p ~/.cargo/
echo "" > ~/.cargo/config.toml
echo "[registry]" >> ~/.cargo/config.toml
echo 'cscherr = "cscherr"' >> ~/.cargo/config.toml
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 fmt
run: cargo fmt --all
- name: cargo test
run: cargo test --all-features --all-targets
- name: commit back to repository
uses: stefanzweifel/git-auto-commit-action@v5
with:
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
commit_message: automatic cargo CI changes

View File

@ -1,7 +0,0 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
# Check for updates every Monday
schedule:
interval: "weekly"

View File

@ -1,16 +1,10 @@
name: Rust CI name: cargo devel CI
on: on:
pull_request:
branches:
- '**'
push: push:
branches: branches:
- '**' - '**'
# - '!master' # - '!master'
env:
CARGO_TERM_COLOR: always
jobs: jobs:
CI: CI:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -25,9 +19,7 @@ jobs:
- name: install rust - name: install rust
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
- name: install additional rust things - name: install additional rust things
run: | run: rustup component add rustfmt
rustup component add rustfmt
rustup component add clippy
- name: config custom registry - name: config custom registry
run: | run: |
mkdir -p ~/.cargo/ mkdir -p ~/.cargo/
@ -37,17 +29,17 @@ jobs:
echo '[registries.cscherr]' >> ~/.cargo/config.toml echo '[registries.cscherr]' >> ~/.cargo/config.toml
echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml
cat ~/.cargo/config.toml cat ~/.cargo/config.toml
- name: cargo clippy check - name: cargo check
run: cargo clippy --all-features --all-targets --workspace run: cargo check --all-features --all-targets
- name: cargo clippy fix - name: cargo fix
run: cargo clippy --fix --all-features --all-targets --workspace run: cargo fix --all-features --all-targets
- name: cargo fmt - name: cargo fmt
run: cargo fmt --all run: cargo fmt --all
- name: cargo test - name: cargo test
run: cargo test --all-features --all-targets --workspace run: cargo test --all-features --all-targets
- name: commit back to repository - name: commit back to repository
uses: stefanzweifel/git-auto-commit-action@v5 uses: stefanzweifel/git-auto-commit-action@v5
with: with:
# Optional. Commit message for the created commit. # Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes" # Defaults to "Apply automatic changes"
commit_message: "ci: automatic Rust CI changes" commit_message: automatic cargo CI changes

View File

@ -1,54 +0,0 @@
name: Release-plz
permissions:
pull-requests: write
contents: write
on:
push:
branches:
- master
- main
jobs:
# Release unpublished packages.
release-plz-release:
name: Release-plz release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Create a PR with the new versions and changelog, preparing the next release.
release-plz-pr:
name: Release-plz PR
runs-on: ubuntu-latest
concurrency:
group: release-plz-${{ github.ref }}
cancel-in-progress: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/release-plz-action@v0.5
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

View File

@ -1,6 +1,6 @@
[package] [package]
name = "hedu" name = "hedu"
version = "0.2.1" version = "0.1.1"
edition = "2021" edition = "2021"
publish = true publish = true
authors = ["Christoph J. Scherr <software@cscherr.de>"] authors = ["Christoph J. Scherr <software@cscherr.de>"]
@ -12,9 +12,8 @@ repository = "https://git.cscherr.de/PlexSheep/hedu"
keywords = ["hexdumper"] keywords = ["hexdumper"]
[dependencies] [dependencies]
libpt = { version = "0.5.1", features = [ libpt = { version = "0.3.11", features = ["log", "bintols"] }
"bintols",
"log",
], default-features = false }
clap = { version = "4.4.4", features = ["derive", "help"] } 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" anyhow = "1.0.79"

View File

@ -2,14 +2,13 @@
![Project badge](https://img.shields.io/badge/language-Rust-blue.svg) ![Project badge](https://img.shields.io/badge/language-Rust-blue.svg)
![Crates.io License](https://img.shields.io/crates/l/hedu) ![Crates.io License](https://img.shields.io/crates/l/hedu)
![GitHub Release](https://img.shields.io/github/v/release/PlexSheep/hedu) ![Gitea Release](https://img.shields.io/gitea/v/release/PlexSheep/hedu?gitea_url=https%3A%2F%2Fgit.cscherr.de)
![GitHub language count](https://img.shields.io/github/languages/count/PlexSheep/hedu) ![Gitea language count](https://img.shields.io/gitea/languages/count/PlexSheep/hedu?gitea_url=https%3A%2F%2Fgit.cscherr.de)
[![Rust CI](https://github.com/PlexSheep/hedu/actions/workflows/cargo.yaml/badge.svg)](https://github.com/PlexSheep/hedu/actions/workflows/cargo.yaml) [![cargo checks and tests](https://github.com/PlexSheep/hedu/actions/workflows/cargo.yaml/badge.svg)](https://github.com/PlexSheep/hedu/actions/workflows/cargo.yaml)
Hex dumping tool written in Rust. Hex dumping tool written in Rust.
* [GitHub](https://github.com/PlexSheep/hedu) * [Original Repository](https://git.cscherr.de/PlexSheep/hedu)
* [GitHub Mirror](https://github.com/PlexSheep/hedu)
* [crates.io](https://crates.io/crates/hedu) * [crates.io](https://crates.io/crates/hedu)
* [docs.rs](https://docs.rs/crate/hedu/) * [docs.rs](https://docs.rs/crate/hedu/)

View File

@ -4,10 +4,10 @@ NEW_VERSION=$(cat Cargo.toml | rg '^\s*version\s*=\s*"([^"]*)"\s*$' -or '$1')
GIT_COMMIT_SHA=$(git rev-parse HEAD) GIT_COMMIT_SHA=$(git rev-parse HEAD)
REPO=${PWD##*/} # name of cwd REPO=${PWD##*/} # name of cwd
BODY=" BODY="
$(git log $(git describe --tags --abbrev=0)..HEAD --pretty="- %s" --oneline --no-decorate) $(git log $(git describe --tags --abbrev=0)..HEAD --pretty="- %s" --oneline --decorate)
" "
USER=PlexSheep USER=PlexSheep
git tag "v$NEW_VERSION" || echo "could not tag" git tag "v$NEW_VERSION-test" || echo "could not tag"
curl -X 'POST' \ curl -X 'POST' \
'https://git.cscherr.de/api/v1/repos/PlexSheep/'$REPO'/releases' \ 'https://git.cscherr.de/api/v1/repos/PlexSheep/'$REPO'/releases' \
-H 'accept: application/json' \ -H 'accept: application/json' \

View File

@ -9,7 +9,7 @@ use libpt::log::{debug, error, trace, warn};
pub const BYTES_PER_LINE: usize = 16; pub const BYTES_PER_LINE: usize = 16;
pub const LINE_SEP_HORIZ: char = '─'; pub const LINE_SEP_HORIZ: char = '─';
pub const LINE_SEP_VERT: char = '│'; pub const LINE_SEP_VERT: char = '│';
pub const CHAR_BORDER: &str = "|"; pub const CHAR_BORDER: &'static str = "|";
pub trait DataSource: Read { pub trait DataSource: Read {
fn skip(&mut self, length: usize) -> std::io::Result<()>; 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); self.display_buf += &format!("{:08X} {LINE_SEP_VERT} ", self.data_idx);
if self.len != 0 { if self.len != 0 {
for i in 0..self.len { for i in 0..self.len {
if i % BYTES_PER_LINE == BYTES_PER_LINE / 2 { if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
self.display_buf += " "; self.display_buf += " ";
} }
self.display_buf += &format!("{:02X} ", self.buf[self.alt_buf][i]); self.display_buf += &format!("{:02X} ", self.buf[self.alt_buf][i]);
} }
if self.len == BYTES_PER_LINE / 2 { if self.len == BYTES_PER_LINE / 2 {
self.display_buf += " "; self.display_buf += " "
} }
for i in 0..(BYTES_PER_LINE - self.len) { for i in 0..(BYTES_PER_LINE - self.len) {
if i % BYTES_PER_LINE == BYTES_PER_LINE / 2 { if i as usize % BYTES_PER_LINE == BYTES_PER_LINE / 2 {
self.display_buf += " "; self.display_buf += " ";
} }
self.display_buf += " "; self.display_buf += " ";
@ -195,7 +195,7 @@ impl Hedu {
self.sep(); self.sep();
self.display_buf += &format!( self.display_buf += &format!(
"{:08X} {LINE_SEP_VERT} read total: {:<8} {:<15}", "{:08X} {LINE_SEP_VERT} read total:\t\t {:<8} {:<15}",
self.rd_counter, self.rd_counter,
humanbytes(self.rd_counter), humanbytes(self.rd_counter),
format!("({} B)", self.rd_counter) format!("({} B)", self.rd_counter)
@ -237,7 +237,7 @@ impl Hedu {
/// interpret characters for the --chars option /// interpret characters for the --chars option
fn mask_chars(c: char) -> char { fn mask_chars(c: char) -> char {
if c.is_ascii_graphic() { if c.is_ascii_graphic() {
c return c;
} else if c == '\n' { } else if c == '\n' {
return '↩'; return '↩';
} else if c == ' ' { } else if c == ' ' {

View File

@ -5,12 +5,13 @@
use std::{fs::File, io::IsTerminal, path::PathBuf}; use std::{fs::File, io::IsTerminal, path::PathBuf};
use libpt::log::{error, trace, warn, Level, Logger}; use libpt::log::*;
use clap::Parser; use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity};
mod dumper; mod dumper;
use dumper::{DataSource, Hedu}; use dumper::*;
#[derive(Debug, Clone, Parser)] #[derive(Debug, Clone, Parser)]
#[command( #[command(
@ -28,9 +29,10 @@ Author: {author-with-newline}
)] )]
/// Hexdumper written in Rust /// Hexdumper written in Rust
pub struct Cli { pub struct Cli {
/// show more details // clap_verbosity_flag seems to make this a global option implicitly
#[arg(short, long)] /// set a verbosity, multiple allowed (f.e. -vvv)
pub verbose: bool, #[command(flatten)]
pub verbose: Verbosity<InfoLevel>,
/// show additional logging meta data /// show additional logging meta data
#[arg(long)] #[arg(long)]
@ -55,22 +57,17 @@ pub struct Cli {
/// a data source, probably a file. /// a data source, probably a file.
/// ///
/// If left empty or set as "-", the program will read from stdin. /// If left empty or set as "-", the program will read from stdin.
///
/// Directories cannot be dumped.
pub data_source: Vec<String>, pub data_source: Vec<String>,
} }
fn main() { fn main() {
let mut cli = cli_parse(); let mut cli = cli_parse();
let mut sources: Vec<Box<dyn DataSource>> = Vec::new(); let mut sources: Vec<Box<dyn DataSource>> = Vec::new();
if !cli.data_source.is_empty() && !cli.data_source.contains(&"-".to_string()) { if cli.data_source.len() > 0 && cli.data_source[0] != "-" {
for data_source in &cli.data_source { for data_source in &cli.data_source {
let data_source: PathBuf = PathBuf::from(data_source); let data_source: PathBuf = PathBuf::from(data_source);
if data_source.is_dir() { if data_source.is_dir() {
warn!( warn!("Not a file {:?}, skipping", data_source);
"'{:?}' is a directory and cannot be dumped, skipping",
data_source
);
// std::process::exit(1); // std::process::exit(1);
continue; continue;
} }
@ -92,20 +89,23 @@ fn main() {
} }
// just for the little header // just for the little header
cli.data_source = Vec::new(); cli.data_source = Vec::new();
cli.data_source.push("stdin".to_string()); cli.data_source.push(format!("stdin"));
sources.push(Box::new(stdin)); sources.push(Box::new(stdin));
} }
for (i, source) in sources.iter_mut().enumerate() { for (i, source) in sources.iter_mut().enumerate() {
let mut config = Hedu::new(cli.chars, cli.skip, cli.show_identical, cli.limit); let mut config = Hedu::new(cli.chars, cli.skip, cli.show_identical, cli.limit);
// FIXME: find a better way to get the file name // FIXME: find a better way to get the file name
// Currently, skipped sources make an extra newline here. // Currently, skipped sources make an extra newline here.
if config.chars { match config.chars {
println!("{:─^80}", format!(" {} ", cli.data_source[i])); false => {
} else { println!("{:─^59}", format!(" {} ", cli.data_source[i]));
println!("{:─^59}", format!(" {} ", cli.data_source[i])); }
true => {
println!("{:─^80}", format!(" {} ", cli.data_source[i]));
}
} }
match config.dump(&mut **source) { match config.dump(&mut **source) {
Ok(()) => (), Ok(_) => (),
Err(err) => { Err(err) => {
error!("Could not dump data of file: {err}"); error!("Could not dump data of file: {err}");
std::process::exit(3); std::process::exit(3);
@ -119,16 +119,21 @@ fn main() {
fn cli_parse() -> Cli { fn cli_parse() -> Cli {
let cli = Cli::parse(); let cli = Cli::parse();
let ll: Level = if cli.verbose { let ll: Level = match cli.verbose.log_level().unwrap().as_str() {
Level::INFO "TRACE" => Level::TRACE,
} else { "DEBUG" => Level::DEBUG,
Level::DEBUG "INFO" => Level::INFO,
"WARN" => Level::WARN,
"ERROR" => Level::ERROR,
_ => {
unreachable!();
}
}; };
if cli.meta { if cli.meta {
let _ = Logger::builder().max_level(ll).build(); Logger::init(None, Some(ll), false).expect("could not initialize Logger");
} else { } else {
// less verbose version // less verbose version
let _ = Logger::builder().show_time(false).build(); Logger::init_mini(Some(ll)).expect("could not initialize Logger");
} }
cli return cli;
} }