Crates.io | systemd_service_parser |
lib.rs | systemd_service_parser |
version | 0.1.2 |
source | src |
created_at | 2024-11-21 07:07:37.332078 |
updated_at | 2024-11-21 07:24:35.313215 |
description | A simple systemd service file parser |
homepage | |
repository | |
max_upload_size | |
id | 1455798 |
size | 15,800 |
A simple systemd service file parser written on Rust using pest
library which extracts sections and their key-value pairs.
WHITESPACE = _{ " " | "\t" } - ignores whitespaces
file = { SOI ~ (SECTION | COMMENT | NEWLINE)+ ~ EOI } - The file can consist of section definitions, comments and newlines COMMENT = { "#" ~ (!NEWLINE ~ ANY)* ~ NEWLINE } SECTION = { HEADER ~ NEWLINE+ ~ KEY_VALUE* ~ NEWLINE* } HEADER = { "[" ~ ASCII_ALPHANUMERIC+ ~ "]" } - Section definition KEY_VALUE = { KEY ~ "=" ~ VALUE ~ NEWLINE } - Key-value pairs KEY = { (ASCII_ALPHANUMERIC | "-" | "_")+ } VALUE = { (!NEWLINE ~ ANY)* } NEWLINE = _{ "\r\n" | "\n" }
[Unit]
Description=A systemd service.
[Service]
ExecStart=/usr/bin/service
[Install]
WantedBy=multi-user.target
cargo run -- test.service
Output:
{
"sections": [
{
"header": "Unit",
"key_values": [
{
"key": "Description",
"value": "A systemd service."
}
]
},
{
"header": "Service",
"key_values": [
{
"key": "ExecStart",
"value": "/usr/bin/service"
}
]
},
{
"header": "Install",
"key_values": [
{
"key": "WantedBy",
"value": "multi-user.target"
}
]
}
]
}
crates.io - https://crates.io/crates/systemd_service_parser docs.rs - https://docs.rs/systemd_service_parser/0.1.0/systemd_service_parser