mirror of
https://github.com/orhun/systeroid
synced 2024-07-05 17:08:36 +00:00
refactor(kernel): construct the path in-place for sysctl sections
This commit is contained in:
parent
8813bb9486
commit
51e8777c5c
|
@ -53,9 +53,12 @@ impl SysctlSection {
|
|||
]
|
||||
}
|
||||
|
||||
/// Returns the sysctl section as a file with `.rst` extension.
|
||||
pub fn as_file(&self) -> PathBuf {
|
||||
Path::new(&self.to_string()).with_extension("rst")
|
||||
/// Returns the path of the sysctl section.
|
||||
pub fn as_path(&self, kernel_docs: &Path) -> PathBuf {
|
||||
kernel_docs
|
||||
.join("admin-guide")
|
||||
.join("sysctl")
|
||||
.join(Path::new(&self.to_string()).with_extension("rst"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ pub mod args;
|
|||
|
||||
use crate::args::Args;
|
||||
use rayon::prelude::*;
|
||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||
use std::sync::Mutex;
|
||||
use systeroid_core::docs::{Documentation, SysctlSection};
|
||||
use systeroid_core::error::{Error, Result};
|
||||
|
@ -20,22 +19,13 @@ pub fn run(args: Args) -> Result<()> {
|
|||
let mut sysctl = Sysctl::init()?;
|
||||
|
||||
let param_docs = if let Some(kernel_docs) = args.kernel_docs {
|
||||
let sysctl_docs = kernel_docs.join("admin-guide").join("sysctl");
|
||||
if !sysctl_docs.exists() {
|
||||
return Err(IoError::new(
|
||||
IoErrorKind::Other,
|
||||
format!("cannot find sysctl documentation: {:?}", sysctl_docs),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
let param_docs = Mutex::new(Vec::new());
|
||||
SysctlSection::variants().par_iter().try_for_each(|s| {
|
||||
let mut param_docs = param_docs
|
||||
.lock()
|
||||
.map_err(|e| Error::ThreadLockError(e.to_string()))?;
|
||||
let mut parse = |section: SysctlSection| -> Result<()> {
|
||||
let docs = reader::read_to_string(&sysctl_docs.join(section.as_file()))?;
|
||||
let docs = reader::read_to_string(§ion.as_path(&kernel_docs))?;
|
||||
param_docs.extend(RstParser::parse_docs(&docs, section)?);
|
||||
Ok(())
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user