generated from PlexSheep/baserepo
early hedu
Cargo Check, Format, Fix and Test / cargo CI (push) Successful in 2m20s
Details
Cargo Check, Format, Fix and Test / cargo CI (push) Successful in 2m20s
Details
This commit is contained in:
parent
b7fbef73b4
commit
3f59e99b88
73
Cargo.toml
73
Cargo.toml
|
@ -1,20 +1,16 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
".",
|
".",
|
||||||
"members/libpt-core",
|
"members/libpt-core",
|
||||||
"members/libpt-bintols",
|
"members/libpt-bintols",
|
||||||
"members/libpt-math",
|
"members/libpt-math",
|
||||||
"members/libpt-bin",
|
"members/libpt-bin",
|
||||||
"members/libpt-log",
|
"members/libpt-log",
|
||||||
"members/libpt-net",
|
"members/libpt-net",
|
||||||
"members/libpt-hedu",
|
"members/libpt-hedu",
|
||||||
]
|
|
||||||
default-members = [
|
|
||||||
".",
|
|
||||||
"members/libpt-bin",
|
|
||||||
"members/libpt-core",
|
|
||||||
]
|
]
|
||||||
|
default-members = [".", "members/libpt-bin", "members/libpt-core"]
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
publish = true
|
publish = true
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
|
@ -26,7 +22,11 @@ readme = "README.md"
|
||||||
homepage = "https://git.cscherr.de/PlexSheep/libpt"
|
homepage = "https://git.cscherr.de/PlexSheep/libpt"
|
||||||
repository = "https://git.cscherr.de/PlexSheep/libpt"
|
repository = "https://git.cscherr.de/PlexSheep/libpt"
|
||||||
keywords = ["cli", "library"]
|
keywords = ["cli", "library"]
|
||||||
categories = ["command-line-utilities", "development-tools", "development-tools::ffi"]
|
categories = [
|
||||||
|
"command-line-utilities",
|
||||||
|
"development-tools",
|
||||||
|
"development-tools::ffi",
|
||||||
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
|
@ -47,39 +47,32 @@ keywords.workspace = true
|
||||||
categories.workspace = true
|
categories.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["log"]
|
default = ["log", "core"]
|
||||||
all = [
|
all = ["default", "math", "log", "bintols", "net", "ccc", "hedu", "core"]
|
||||||
"default",
|
core = []
|
||||||
"math",
|
fw = []
|
||||||
"log",
|
math = []
|
||||||
"bintols",
|
log = []
|
||||||
"net",
|
|
||||||
"ccc",
|
|
||||||
"hedu"
|
|
||||||
]
|
|
||||||
fw = []
|
|
||||||
math = []
|
|
||||||
log = []
|
|
||||||
bintols = []
|
bintols = []
|
||||||
net = []
|
net = []
|
||||||
ccc = ["math"]
|
ccc = ["math"]
|
||||||
hedu = ["bintols"]
|
hedu = ["bintols"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "libpt"
|
name = "libpt"
|
||||||
crate-type = [
|
crate-type = [
|
||||||
"dylib", # .dll, .so, .dynlib
|
"dylib", # .dll, .so, .dynlib
|
||||||
"staticlib", # .lib, .a
|
"staticlib", # .lib, .a
|
||||||
"rlib"
|
"rlib",
|
||||||
]
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libpt-bintols = { path = "members/libpt-bintols" }
|
libpt-bintols = { path = "members/libpt-bintols" }
|
||||||
libpt-core = { path = "members/libpt-core" }
|
libpt-core = { path = "members/libpt-core" }
|
||||||
libpt-hedu = { path = "members/libpt-hedu" }
|
libpt-hedu = { path = "members/libpt-hedu" }
|
||||||
libpt-log = { path = "members/libpt-log" }
|
libpt-log = { path = "members/libpt-log" }
|
||||||
libpt-math = { path = "members/libpt-math" }
|
libpt-math = { path = "members/libpt-math" }
|
||||||
libpt-net = { path = "members/libpt-net" }
|
libpt-ccc = { path = "members/libpt-ccc" }
|
||||||
libpt-ccc = { path = "members/libpt-ccc" }
|
libpt-net = { path = "members/libpt-net" }
|
||||||
|
|
|
@ -19,6 +19,10 @@ categories.workspace = true
|
||||||
name = "ccc"
|
name = "ccc"
|
||||||
path = "src/ccc/mod.rs"
|
path = "src/ccc/mod.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "hedu"
|
||||||
|
path = "src/hedu/mod.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "libpt"
|
name = "libpt"
|
||||||
path = "src/main/mod.rs"
|
path = "src/main/mod.rs"
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
//! # Executable for the hedu submodule
|
||||||
|
//!
|
||||||
|
//! Dump data to a fancy format.
|
||||||
|
|
||||||
|
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// we want docs
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
#![warn(rustdoc::missing_crate_level_docs)]
|
||||||
|
// we want Debug everywhere.
|
||||||
|
#![warn(missing_debug_implementations)]
|
||||||
|
// enable clippy's extra lints, the pedantic version
|
||||||
|
#![warn(clippy::pedantic)]
|
||||||
|
|
||||||
|
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
use libpt::{hedu::*, log::*};
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
io::{BufRead, BufReader},
|
||||||
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
|
||||||
|
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// short about section displayed in help
|
||||||
|
const ABOUT_ROOT: &'static str = r##"
|
||||||
|
Dumps data in fancy formats
|
||||||
|
"##;
|
||||||
|
/// longer about section displayed in help, is combined with [the short help](ABOUT_ROOT)
|
||||||
|
static LONG_ABOUT_ROOT: &'static str = r##"
|
||||||
|
|
||||||
|
libpt is a personal general purpose library, offering this executable, a python module and a
|
||||||
|
dynamic library.
|
||||||
|
"##;
|
||||||
|
|
||||||
|
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// defines CLI interface
|
||||||
|
#[derive(Debug, Clone, Parser)]
|
||||||
|
#[command(
|
||||||
|
author,
|
||||||
|
version,
|
||||||
|
about = ABOUT_ROOT,
|
||||||
|
long_about = format!("{}{}", ABOUT_ROOT ,LONG_ABOUT_ROOT),
|
||||||
|
help_template =
|
||||||
|
r#"libpt: {version}{about-section}Author:
|
||||||
|
{author-with-newline}
|
||||||
|
{usage-heading} {usage}{all-args}{tab}"#
|
||||||
|
)]
|
||||||
|
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 logger meta
|
||||||
|
#[arg(short, long, global = true)]
|
||||||
|
pub log_meta: bool,
|
||||||
|
|
||||||
|
/// a data source, probably a file
|
||||||
|
pub data_source: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||||
|
fn main() {
|
||||||
|
let cli = cli_parse();
|
||||||
|
debug!("Trying to open '{}'", cli.data_source);
|
||||||
|
let file = match File::open(cli.data_source.clone()) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(err) => {
|
||||||
|
error!("Could not open file '{}': {err}", cli.data_source);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match dump(BufReader::new(file)){
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(err) => {
|
||||||
|
error!("Could not dump data of file: {err}");
|
||||||
|
std::process::exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
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,
|
||||||
|
_ => {
|
||||||
|
eprintln!("'{}' is not a valid loglevel", cli.verbose.to_string());
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if cli.log_meta {
|
||||||
|
Logger::init_customized(
|
||||||
|
false,
|
||||||
|
PathBuf::from("/dev/null"),
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
ll,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.expect("could not initialize Logger");
|
||||||
|
} else {
|
||||||
|
// less verbose version
|
||||||
|
Logger::init_customized(
|
||||||
|
false,
|
||||||
|
PathBuf::from("/dev/null"),
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
ll,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.expect("could not initialize Logger");
|
||||||
|
}
|
||||||
|
return cli;
|
||||||
|
}
|
|
@ -15,3 +15,5 @@ categories.workspace = true
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
|
|
@ -4,3 +4,21 @@
|
||||||
//! module.
|
//! module.
|
||||||
//!
|
//!
|
||||||
//! This crate is currently empty.
|
//! This crate is currently empty.
|
||||||
|
|
||||||
|
use std::{fmt::Debug, io::{BufReader, BufRead, prelude::*, Bytes}};
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
pub fn dump<T>(mut data: BufReader<T>) -> Result<()>
|
||||||
|
where T: Read
|
||||||
|
{
|
||||||
|
for (i, b) in data.bytes().enumerate() {
|
||||||
|
if i % 8 == 0 {
|
||||||
|
print!("{:08X}\t", i);
|
||||||
|
}
|
||||||
|
print!("{:02X?} ", b.unwrap());
|
||||||
|
if i % 8 == 7 {
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Reference in New Issue