Skip to content

Config feature [WIP] - #1

Open
Zirias wants to merge 31 commits into
masterfrom
feature_config
Open

Config feature [WIP]#1
Zirias wants to merge 31 commits into
masterfrom
feature_config

Conversation

@Zirias

@Zirias Zirias commented Jun 8, 2023

Copy link
Copy Markdown
Owner

This attempts to add generic configuration support to libposercore. It is work in progress, the open pull request just ensures the feature branch will be checked using CI builds.

Planned feature set:

  • A parser for command-line arguments
    • Support for POSIX short flags and GNU long flags
    • Support for any arrangement of flag arguments (with/without whitespace, in a queue after collapsed short flags, ...)
    • Support for positional arguments
    • Support for one level of nesting (sub-sections) using a custom colon-delimited format
  • A parser for configuration files
    • Support for a (very limited) subset of TOML
  • Free stacking of parsers, later parsers will append (for lists) or replace earlier values
  • Custom parser callbacks for single elements, custom validator callbacks for elements and sections
  • Auto-generation of:
    • "Usage" messages
    • "Help" messages
    • A sample configuration file

@Zirias
Zirias force-pushed the feature_config branch 4 times, most recently from d85981b to 759386b Compare June 11, 2023 08:47
Zirias added 26 commits June 19, 2023 11:12
Add some API for generic configuration handling and first
implementations for the metadata objects
- Add flag whether an element is required
- Remove default value when creating a Bool element, those are always
  optional and always default to false (0)
"Top level" ConfigSection is done.
* When output doesn't go to a tty, use default width of 80 columns
* When COLUMNS is given in environment, respect it
* Otherwise query actual width from tty
* Enforce lower limit of 24 cols and upper limit of 512 cols
* guard against unavailability of TIOCGWINSZ ioctl
* also support obscure systems using TIOCGSIZE ioctl instead
* don't attempt any ioctl if both aren't available
When output goes to a terminal and would not fit completely, *and* the
PAGER variable is set and non-empty, attempt to automatically pipe it to
the pager.
Also catch child errors after all content was piped
Implemented so far: short flags, positional arguments and plain lists
(no sub-sections)
Also add recursive validation checking for required options and a way to
automatically print the "usage" message and the error(s) when parsing or
validation fails.
* Option to restrict some config element to a specific parser type
* New element type "Action", immediately execute a callback when it is
  found (and stop parsing)
* Convenience functions to automatically add flags for help and version
  output, using this new "Action" type
* For optional ConfigElements, automatically set their default value
  when not found by any parser, except when it is 0 (null-pointer for a
  string, actual numerical 0 for integer or float)
* Provide convenience accessors for the simple types that just return 0
  when no value is set for a specific key
So far, the args parser *always* created a new PSC_Config object for any
subsection. This doesn't hurt when it's the only parser, but is *wrong*
otherwise, it should only do that for a list of subsections, so
different parsers can stack nicely (overriding single values even in
subsections and only appending to lists). Fixed that...
They are explicitly requested by the user, so they should not go to
stderr.
This should avoid unnecessary confusion. If output goes to any other
file (e.g. stderr) that *happens* to point to the terminal, there's
probably a reason for that and paging is not wanted.

This also eliminates the need to reopen /dev/tty in the pager child
process.
Just having the pointer to the currently active parser thread-local
doesn't make the whole process thread-safe; it should be all or nothing.

So far I don't see a reason to use the config functions from threads,
therefore just remove it for now.
Collect as many errors as possible at once, only stop parsing where
really necessary. Validate everything when parsing succeeded.

Also fix a glitch where the original parsing error message was
suppressed if a custom element parser did no action at all.
Zirias added 4 commits June 19, 2023 11:12
* fix a few bugs
* add error messages about missing flag arguments
* require action flags to be the only argument given
* add optional prefix to output formatter (for comments)
* add a struct to define a file parser
* add a stub to create a sample config file
@Zirias
Zirias force-pushed the master branch 2 times, most recently from 0851e49 to 1287cc1 Compare April 11, 2025 09:07
@Zirias
Zirias force-pushed the master branch 2 times, most recently from a8b8b63 to c93e300 Compare April 30, 2025 16:41
@Zirias
Zirias force-pushed the master branch 3 times, most recently from 1ad58a0 to ba5215a Compare May 30, 2025 06:31
@Zirias
Zirias force-pushed the master branch 14 times, most recently from fca9131 to 7aa6332 Compare June 3, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant