mirror of
https://github.com/orhun/systeroid
synced 2024-07-21 10:25:00 +00:00
refactor(parser): use constants for kernel documentation parsers
This commit is contained in:
parent
6f3df91efb
commit
8aca59a897
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -325,6 +325,7 @@ dependencies = [
|
|||
name = "systeroid-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"sysctl",
|
||||
"systeroid-parser",
|
||||
"thiserror",
|
||||
|
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
sysctl = "0.4.2"
|
||||
thiserror = "1.0.29"
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
[dependencies.systeroid-parser]
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -2,8 +2,14 @@
|
|||
|
||||
#![warn(missing_docs, clippy::unwrap_used)]
|
||||
|
||||
/// Linux kernel parameter handler.
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
/// Kernel parameter handler.
|
||||
pub mod sysctl;
|
||||
|
||||
/// Error implementation.
|
||||
pub mod error;
|
||||
|
||||
/// Parsers for the kernel documentation.
|
||||
pub mod parsers;
|
||||
|
|
22
systeroid-core/src/parsers.rs
Normal file
22
systeroid-core/src/parsers.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use systeroid_parser::parser::Parser;
|
||||
use systeroid_parser::regex::RegexBuilder;
|
||||
|
||||
lazy_static! {
|
||||
/// Pre-defined parsers for parsing the kernel documentation.
|
||||
pub static ref PARSERS: Vec<Parser<'static>> = vec![
|
||||
Parser {
|
||||
glob_path: "admin-guide/sysctl/*.rst",
|
||||
regex: RegexBuilder::new("^\n([a-z].*)\n[=,-]{2,}+\n\n")
|
||||
.multi_line(true)
|
||||
.build()
|
||||
.expect("failed to compile regex"),
|
||||
},
|
||||
Parser {
|
||||
glob_path: "networking/*-sysctl.rst",
|
||||
regex: RegexBuilder::new("^([a-zA-Z0-9_/-]+)[ ]-[ ][a-zA-Z].*$")
|
||||
.multi_line(true)
|
||||
.build()
|
||||
.expect("failed to compile regex"),
|
||||
},
|
||||
];
|
||||
}
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#![warn(missing_docs, clippy::unwrap_used)]
|
||||
|
||||
/// Export regex crate.
|
||||
pub use regex;
|
||||
|
||||
/// Document parser.
|
||||
pub mod parser;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use crate::args::Args;
|
|||
use rayon::prelude::*;
|
||||
use std::sync::Mutex;
|
||||
use systeroid_core::error::{Error, Result};
|
||||
use systeroid_core::parsers::PARSERS;
|
||||
use systeroid_core::sysctl::Sysctl;
|
||||
use systeroid_parser::document::Document;
|
||||
use systeroid_parser::parser::Parser;
|
||||
|
@ -17,16 +18,9 @@ use systeroid_parser::parser::Parser;
|
|||
pub fn run(args: Args) -> Result<()> {
|
||||
let mut sysctl = Sysctl::init()?;
|
||||
|
||||
let parsers = vec![
|
||||
Parser::new("admin-guide/sysctl/*.rst", "^\n([a-z].*)\n[=,-]{2,}+\n\n")?,
|
||||
Parser::new(
|
||||
"networking/*-sysctl.rst",
|
||||
"^([a-zA-Z0-9_/-]+)[ ]-[ ][a-zA-Z].*$",
|
||||
)?,
|
||||
];
|
||||
let documents = if let Some(kernel_docs) = args.kernel_docs {
|
||||
let documents = Mutex::new(Vec::new());
|
||||
parsers.par_iter().try_for_each(|s| {
|
||||
PARSERS.par_iter().try_for_each(|s| {
|
||||
let mut documents = documents
|
||||
.lock()
|
||||
.map_err(|e| Error::ThreadLockError(e.to_string()))?;
|
||||
|
|
Loading…
Reference in a new issue