#parser #sysctl

nparse

Parser in rust for specific use-cases

9 releases

0.0.10 Oct 21, 2023
0.0.9 Oct 20, 2023
0.0.4 Apr 29, 2021
0.0.3 Jan 31, 2021

#641 in Parser implementations

Download history 6/week @ 2024-06-08 20/week @ 2024-06-15 2/week @ 2024-06-22 8/week @ 2024-06-29 12/week @ 2024-07-06 3/week @ 2024-08-31 94/week @ 2024-09-07 27/week @ 2024-09-14 24/week @ 2024-09-21

148 downloads per month

MIT license

25KB
489 lines

nparse 0.0.10

Build Status

Parser for various Rust Strings.

Parsers for:

  • Well Indent Strings (eg: dmidecode output)
  • KV pair Strings (eg: lscpu output)
  • Multiline KV pair strings (eg: systeminfo output of windows)
  • Dotted tree Strings (eg: sysctl output)

Requirements

  • Rust 1.50+

Usage

nparse = "0.0.10"

Example use

  • Converting an Indent string into json
use std::{fs::File, io::Read};
use nparse::*;

fn main () {
    let path = "data/dmidecode.txt";
    let mut out = String::new();
    {
        let mut f = File::open(path).unwrap();
        f.read_to_string(&mut out).unwrap();
    }
    let result = out.indent_to_json();
    println!("{:?}", result);
}
  • Converting a K:V string into json
use std::{fs::File, io::Read};
use nparse::*;

fn main () {
    let path = "data/lscpu.txt";
    let mut out = String::new();
    {
        let mut f = File::open(path).unwrap();
        f.read_to_string(&mut out).unwrap();
    }
    let result = out.kv_str_to_json();
    println!("{:?}", result);
}
  • Converting a K=V string into json
use std::{fs::File, io::Read};
use nparse::*;

fn main () {
    let path = "data/os-release.txt";
    let mut out = String::new();
    {
        let mut f = File::open(path).unwrap();
        f.read_to_string(&mut out).unwrap();
    }
    let result = out.kev_str_to_json();
    println!("{:?}", result);
}
  • Converting a dotted string into json (eg: parent.sub.sub: val)
use std::{fs::File, io::Read};
use nparse::*;

fn main () {
    let path = "data/sysctl.txt";
    let mut out = String::new();
    {
        let mut f = File::open(path).unwrap();
        f.read_to_string(&mut out).unwrap();
    }
    let result = out.dotted_tree_to_json();
    println!("{:?}", result);
}

Tests, Build

  • Test
cargo t 
  • Build Release
cargo b --release

Examples

  • Parse dmidecode output to json
cargo run --example dmidecode
  • Parse sysctl output to json
cargo run --example sysctl
  • Parse lscpu to json
cargo run --example lscpu
  • Parse windows systeminfo to json
cargo run --example systeminfo

Dependencies

~2–2.7MB
~50K SLoC