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"
|
anyhow = "1.0.83"
|
||||||
clap = { version = "4.5.4", features = ["derive"] }
|
clap = { version = "4.5.4", features = ["derive"] }
|
||||||
fast32 = "1.0.2"
|
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"
|
num = "0.4.3"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use clap::{ArgGroup, Parser};
|
use clap::{ArgGroup, Parser};
|
||||||
use libpt::bintols::{join, split};
|
use libpt::bintols::{join, split};
|
||||||
|
use libpt::cli::args::VerbosityLevel;
|
||||||
|
use libpt::log::debug;
|
||||||
|
|
||||||
/// The number type [numf](crate) uses
|
/// The number type [numf](crate) uses
|
||||||
pub type NumberType = u128;
|
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.
|
/// The numbers may be left empty at first, if numbers are provided from the stdin.
|
||||||
numbers: Vec<NumberType>,
|
numbers: Vec<NumberType>,
|
||||||
|
|
||||||
|
#[command(flatten)]
|
||||||
|
pub(crate) verbosity: VerbosityLevel,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormatOptions {
|
impl FormatOptions {
|
||||||
|
@ -242,6 +247,7 @@ impl Default for FormatOptions {
|
||||||
numbers: vec![],
|
numbers: vec![],
|
||||||
rand: 0,
|
rand: 0,
|
||||||
rand_max: NumberType::MAX,
|
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;
|
mod format;
|
||||||
use format::*;
|
use format::*;
|
||||||
|
use libpt::log::debug;
|
||||||
use numf::format::numf_parser;
|
use numf::format::numf_parser;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
// try to read from stdin first, appending the numbers we read to the FormatOptions
|
// try to read from stdin first, appending the numbers we read to the FormatOptions
|
||||||
let mut options = FormatOptions::parse();
|
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 mut stdin_nums = Vec::new();
|
||||||
let stdin = std::io::stdin();
|
let stdin = std::io::stdin();
|
||||||
// only accept numbers from stdin if the stdin is not an interactive terminal
|
// only accept numbers from stdin if the stdin is not an interactive terminal
|
||||||
|
|
Reference in New Issue