generated from PlexSheep/rs-base
feat: add logger
This commit is contained in:
parent
e92af8acfa
commit
727b84e56b
|
@ -17,7 +17,6 @@ categories = ["command-line-utilities", "encoding"]
|
|||
anyhow = "1.0.83"
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
fast32 = "1.0.2"
|
||||
libpt = { version = "0.5.1", features = ["bintols"], default-features = false }
|
||||
libpt = { version = "0.6.0", features = ["bintols", "log", "cli"] }
|
||||
num = "0.4.3"
|
||||
rand = "0.8.5"
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
use anyhow::anyhow;
|
||||
use clap::{ArgGroup, Parser};
|
||||
use libpt::bintols::{join, split};
|
||||
use libpt::cli::args::VerbosityLevel;
|
||||
use libpt::log::debug;
|
||||
|
||||
/// The number type [numf](crate) uses
|
||||
pub type NumberType = u128;
|
||||
|
@ -127,6 +129,9 @@ pub struct FormatOptions {
|
|||
///
|
||||
/// The numbers may be left empty at first, if numbers are provided from the stdin.
|
||||
numbers: Vec<NumberType>,
|
||||
|
||||
#[command(flatten)]
|
||||
pub(crate) verbosity: VerbosityLevel,
|
||||
}
|
||||
|
||||
impl FormatOptions {
|
||||
|
@ -242,6 +247,7 @@ impl Default for FormatOptions {
|
|||
numbers: vec![],
|
||||
rand: 0,
|
||||
rand_max: NumberType::MAX,
|
||||
verbosity: VerbosityLevel::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -5,11 +5,21 @@ use clap::{CommandFactory, Parser};
|
|||
|
||||
mod format;
|
||||
use format::*;
|
||||
use libpt::log::debug;
|
||||
use numf::format::numf_parser;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
// try to read from stdin first, appending the numbers we read to the FormatOptions
|
||||
let mut options = FormatOptions::parse();
|
||||
let _logger = libpt::log::Logger::builder()
|
||||
.set_level(options.verbosity.level())
|
||||
.display_time(false)
|
||||
.build()
|
||||
.map_err(|e| {
|
||||
eprintln!("could not initialize logger: {e}");
|
||||
});
|
||||
debug!("logger active");
|
||||
|
||||
let mut stdin_nums = Vec::new();
|
||||
let stdin = std::io::stdin();
|
||||
// only accept numbers from stdin if the stdin is not an interactive terminal
|
||||
|
|
Reference in New Issue