mirror of
https://github.com/orhun/systeroid
synced 2024-07-03 07:58:45 +00:00
feat(error): add custom error implementation
This commit is contained in:
parent
e55f512689
commit
81c9fc8fe2
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -70,6 +70,9 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "kparams-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kparams-parser"
|
||||
|
@ -176,6 +179,26 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.14.0"
|
||||
|
|
|
@ -5,3 +5,4 @@ authors = ["Orhun Parmaksız <orhunparmaksiz@gmail.com>"]
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "1.0.29"
|
||||
|
|
12
kparams-core/src/error.rs
Normal file
12
kparams-core/src/error.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use thiserror::Error as ThisError;
|
||||
|
||||
/// Custom error type.
|
||||
#[derive(Debug, ThisError)]
|
||||
pub enum Error {
|
||||
/// Error that might occur during I/O operations.
|
||||
#[error("IO error: `{0}`")]
|
||||
IoError(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
/// Type alias for the standard [`Result`] type.
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
|
@ -7,3 +7,6 @@ pub mod kernel;
|
|||
|
||||
/// File reader.
|
||||
pub mod reader;
|
||||
|
||||
/// Error handler.
|
||||
pub mod error;
|
||||
|
|
23
kparams/src/lib.rs
Normal file
23
kparams/src/lib.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
//! kparams
|
||||
|
||||
#![warn(missing_docs, clippy::unwrap_used)]
|
||||
|
||||
use kparams_core::error::Result;
|
||||
use kparams_core::reader;
|
||||
use kparams_parser::parser::RstParser;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Runs `kparams`.
|
||||
pub fn run() -> Result<()> {
|
||||
let kernel_docs = PathBuf::from("/usr/share/doc/linux");
|
||||
let sysctl_docs = kernel_docs.join("admin-guide").join("sysctl");
|
||||
let kernel_section = reader::read_to_string(&sysctl_docs.join("kernel.rst"))?;
|
||||
|
||||
let kernel_section_docs = RstParser::parse_docs(&kernel_section);
|
||||
for kernel_parameter in kernel_section_docs.parameters {
|
||||
println!("## {}", kernel_parameter.name);
|
||||
println!("{}", kernel_parameter.description);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,15 +1,8 @@
|
|||
use kparams_core::reader;
|
||||
use kparams_parser::parser::RstParser;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
|
||||
fn main() {
|
||||
let kernel_docs = PathBuf::from("/usr/share/doc/linux");
|
||||
let sysctl_docs = kernel_docs.join("admin-guide").join("sysctl");
|
||||
let kernel_section = reader::read_to_string(&sysctl_docs.join("kernel.rst")).unwrap();
|
||||
|
||||
let kernel_section_docs = RstParser::parse_docs(&kernel_section);
|
||||
for kernel_parameter in kernel_section_docs.parameters {
|
||||
println!("## {}", kernel_parameter.name);
|
||||
println!("{}", kernel_parameter.description);
|
||||
match kparams::run() {
|
||||
Ok(_) => process::exit(0),
|
||||
Err(_) => process::exit(1),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user