mirror of
https://github.com/orhun/systeroid
synced 2024-07-08 19:55:51 +00:00
refactor(lib): remove references in kernel types
This commit is contained in:
parent
6e440b31c8
commit
0795f8c8bc
|
@ -2,7 +2,7 @@ use std::fmt::{self, Display, Formatter};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
/// Sections of the sysctl documentation.
|
/// Sections of the sysctl documentation.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum SysctlSection {
|
pub enum SysctlSection {
|
||||||
/// Documentation for `/proc/sys/abi/*`
|
/// Documentation for `/proc/sys/abi/*`
|
||||||
Abi,
|
Abi,
|
||||||
|
@ -28,15 +28,15 @@ impl Display for SysctlSection {
|
||||||
|
|
||||||
impl SysctlSection {
|
impl SysctlSection {
|
||||||
/// Returns the variants.
|
/// Returns the variants.
|
||||||
pub fn iter() -> &'static [&'static SysctlSection] {
|
pub fn variants() -> &'static [SysctlSection] {
|
||||||
&[
|
&[
|
||||||
&Self::Abi,
|
Self::Abi,
|
||||||
&Self::Fs,
|
Self::Fs,
|
||||||
&Self::Kernel,
|
Self::Kernel,
|
||||||
&Self::Net,
|
Self::Net,
|
||||||
&Self::Sunrpc,
|
Self::Sunrpc,
|
||||||
&Self::User,
|
Self::User,
|
||||||
&Self::Vm,
|
Self::Vm,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,18 +48,18 @@ impl SysctlSection {
|
||||||
|
|
||||||
/// Representation of a kernel parameter.
|
/// Representation of a kernel parameter.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Parameter<'a> {
|
pub struct Parameter {
|
||||||
/// Name of the kernel parameter.
|
/// Name of the kernel parameter.
|
||||||
pub name: &'a str,
|
pub name: String,
|
||||||
/// Description of the kernel parameter.
|
/// Description of the kernel parameter.
|
||||||
pub description: &'a str,
|
pub description: String,
|
||||||
/// Section of the kernel parameter.
|
/// Section of the kernel parameter.
|
||||||
pub section: &'a SysctlSection,
|
pub section: SysctlSection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Parameter<'a> {
|
impl Parameter {
|
||||||
/// Constructs a new instance.
|
/// Constructs a new instance.
|
||||||
pub fn new(name: &'a str, description: &'a str, section: &'a SysctlSection) -> Self {
|
pub fn new(name: String, description: String, section: SysctlSection) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
|
|
@ -15,10 +15,7 @@ impl RstParser {
|
||||||
/// Parses the given reStructuredText input and returns the [`kernel parameters`].
|
/// Parses the given reStructuredText input and returns the [`kernel parameters`].
|
||||||
///
|
///
|
||||||
/// [`kernel parameters`]: Parameter
|
/// [`kernel parameters`]: Parameter
|
||||||
pub fn parse_docs<'a>(
|
pub fn parse_docs(input: &str, section: SysctlSection) -> Result<Vec<Parameter>> {
|
||||||
input: &'a str,
|
|
||||||
section: &'a SysctlSection,
|
|
||||||
) -> Result<Vec<Parameter<'a>>> {
|
|
||||||
let mut kernel_parameters = Vec::new();
|
let mut kernel_parameters = Vec::new();
|
||||||
let rst_document =
|
let rst_document =
|
||||||
Self::parse(Rule::document, input).map_err(|e| Error::ParseError(e.to_string()))?;
|
Self::parse(Rule::document, input).map_err(|e| Error::ParseError(e.to_string()))?;
|
||||||
|
@ -27,11 +24,13 @@ impl RstParser {
|
||||||
.collect::<Vec<Title<'_>>>();
|
.collect::<Vec<Title<'_>>>();
|
||||||
for (i, title) in titles.iter().enumerate() {
|
for (i, title) in titles.iter().enumerate() {
|
||||||
kernel_parameters.push(Parameter::new(
|
kernel_parameters.push(Parameter::new(
|
||||||
title.value,
|
title.value.to_string(),
|
||||||
if let Some(next_title) = titles.get(i + 1) {
|
if let Some(next_title) = titles.get(i + 1) {
|
||||||
(input[title.end_pos..next_title.start_pos]).trim()
|
(input[title.end_pos..next_title.start_pos])
|
||||||
|
.trim()
|
||||||
|
.to_string()
|
||||||
} else {
|
} else {
|
||||||
(input[title.end_pos..]).trim()
|
(input[title.end_pos..]).trim().to_string()
|
||||||
},
|
},
|
||||||
section,
|
section,
|
||||||
));
|
));
|
||||||
|
|
|
@ -13,15 +13,16 @@ pub fn run() -> Result<()> {
|
||||||
let kernel_docs = PathBuf::from("/usr/share/doc/linux");
|
let kernel_docs = PathBuf::from("/usr/share/doc/linux");
|
||||||
let sysctl_docs = kernel_docs.join("admin-guide").join("sysctl");
|
let sysctl_docs = kernel_docs.join("admin-guide").join("sysctl");
|
||||||
|
|
||||||
for sysctl_section in SysctlSection::iter() {
|
let mut kernel_parameters = Vec::new();
|
||||||
let sysctl_section_docs =
|
for section in SysctlSection::variants().iter() {
|
||||||
reader::read_to_string(&sysctl_docs.join(sysctl_section.as_file()))?;
|
let docs = reader::read_to_string(&sysctl_docs.join(section.as_file()))?;
|
||||||
let kernel_parameters = RstParser::parse_docs(&sysctl_section_docs, sysctl_section)?;
|
kernel_parameters.extend(RstParser::parse_docs(&docs, *section)?);
|
||||||
|
}
|
||||||
|
|
||||||
for param in kernel_parameters {
|
for param in kernel_parameters {
|
||||||
println!("## {}::{}\n", param.section, param.name);
|
println!("## {}::{}\n", param.section, param.name);
|
||||||
println!("{}\n", param.description);
|
println!("{}\n", param.description);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user