Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

tygoee/systemd-parser

Repository files navigation

Systemd parser

Round-trip systemd configuration file parser.

Warning

This has not been under active developement for a while, and it was stopped while building a pretty big overhaul fixing quite some poor design choices and bugs.

I might pick this project up again when I have the time and means to continue with tygoee/congent

Usage and documentation

  • parse(input, options):
import { parse } from "systemd-parser"
const input = "[Section]\nKey=Value"
const output = parse(input, {
 // A function that executes upon successful assignment.
 // If it returns something, it'll be used as value parser, changing the result
 func: (section: string, key: string, value: string) => {};
 warnFunc: (message: string, lineNum: number, severity: "hint"|"info"|"warning"|"error") => {}; // Ran on warnings
 logWarns: false; // Log parsing warnings to the console
 strict: false; // Make parsing fail on wrong syntax
 includePrefixed: false; // default false, include keys prefixed with X-
 allowedKeys: { Section: [ "Key1", "Key2" ] }; // object of allowed sections and keys. Prefix '-' to ignore a key
 includeDisallowed: false; // include keys not allowed by allowedKeys
})
// output: { "Section": { "Key": [ "Value" ] }}
  • generate(input):
import { generate } from "systemd-parser";
const input = { Section: { Key: ["Value"] } };
const output = generate(input);
// [Section] Key=Value
  • parseDocument(input):
import { parseDocument } from "systemd-parser"
const doc = parseDocument("[Section]\nKey=Value")
// doc.output: { "Section": { "Key": [ "Value" ] }}
doc.add('Section', 'Key', 'ThirdValue')
doc.add('Section', 'Key', 'SecondValue', 1) // insert
// doc.content: [Section] Key=Value Key=SecondValue Key=ThirdValue
doc.set('Section', 'Key' 'OtherValue', 1)
// doc.content: [Section] Key=Value Key=OtherValue Key=ThirdValue
doc.remove('Section', 'Key', 1)
// doc.content: [Section] Key=Value Key=ThirdValue
doc.set('Section', 'Key', 'Value') // resets all instances
// doc.content: [Section] Key=Value
doc.remove('Setion', 'Key', 'Value') // removes all instances
// doc.content: ""

Systemd ini format

Basics of the file format are listed at systemd.syntax(7). For more, see the references below.

References


License

This project uses the MIT license. It uses some of the logic from Red Hat for parsing systemd ini files, which is licensed under both LGPL-2.1+ [1] and Apache-2.0 [2]. For more details, see NOTICE

About

Round-trip systemd configuration file parser.

Topics

Resources

License

Stars

Watchers

Forks

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /