Merge pull request 'v0.2.0' (#7) from devel into master
cargo devel CI / cargo CI (push) Has been cancelled Details

Reviewed-on: #7
This commit is contained in:
Christoph J. Scherr 2024-05-24 09:31:16 +02:00
commit d331c89a79
6 changed files with 47 additions and 47 deletions

View File

@ -16,9 +16,11 @@ 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
run: |
rustup component add rustfmt
rustup component add clippy
- name: config custom registry
run: |
mkdir -p ~/.cargo/
@ -28,16 +30,16 @@ 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 --workspace
- name: cargo clippy fix
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
- 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"

View File

@ -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/
@ -29,14 +31,14 @@ 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 --workspace
- name: cargo clippy fix
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
- name: commit back to repository
uses: stefanzweifel/git-auto-commit-action@v5
with:

View File

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

View File

@ -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' \

View File

@ -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 == ' ' {

View File

@ -5,13 +5,12 @@
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(
@ -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<InfoLevel>,
/// show more details
#[arg(short, long)]
pub verbose: bool,
/// show additional logging meta data
#[arg(long)]
@ -57,17 +55,22 @@ 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<String>,
}
fn main() {
let mut cli = cli_parse();
let mut sources: Vec<Box<dyn DataSource>> = Vec::new();
if cli.data_source.len() > 0 && 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;
}
@ -89,7 +92,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 +108,7 @@ fn main() {
}
}
match config.dump(&mut **source) {
Ok(_) => (),
Ok(()) => (),
Err(err) => {
error!("Could not dump data of file: {err}");
std::process::exit(3);
@ -119,21 +122,16 @@ 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 {
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().show_time(false).build();
}
return cli;
cli
}