~zethra/freedesktop_entry_parser

A library for parsing FreeDesktop entry files
26bc02d2 — zethra 2 months ago
Bump version to 1.1.0
43d89b9a — zethra 2 months ago
Removed unwraps on file io errors
53291907 — zethra 2 months ago
Bump version to 1.0.0

clone

read-only
https://git.sr.ht/~zethra/freedesktop_entry_parser
read/write
git@git.sr.ht:~zethra/freedesktop_entry_parser

You can also use your local clone with git send-email.

#Freedesktop Entry Parser

crates.io docs.rs

A library for parsing FreeDesktop entry files in Rust. These files are used in the Desktop Entry, Icon Theme, and Systemd Unit file. They are similar to ini files but are distinct enough that an ini parse would not work.

#Example Usage

As example input lets use the contents of sshd.service

[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target

[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target

For example, to print the start command we could do this:

use freedesktop_entry_parser::parse_entry;

let entry = parse_entry("./test_data/sshd.service")?;
let start_cmd = entry
    .section("Service")
    .attr("ExecStart")
    .expect("Attribute doesn't exist");
println!("{}", start_cmd);

# Ok::<(), freedesktop_entry_parser::ParseError>(())

This prints /usr/bin/sshd -D

For more extensive documentaion see docs.rs or generate the docs yourself by cloning the repo and running cargo doc. For more examples see the exmaples in the repo.