Config feature [WIP] - #1
Open
Zirias wants to merge 31 commits into
Open
Conversation
Zirias
force-pushed
the
feature_config
branch
4 times, most recently
from
June 11, 2023 08:47
d85981b to
759386b
Compare
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.
* 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
force-pushed
the
master
branch
2 times, most recently
from
April 11, 2025 09:07
0851e49 to
1287cc1
Compare
Zirias
force-pushed
the
master
branch
2 times, most recently
from
April 30, 2025 16:41
a8b8b63 to
c93e300
Compare
Zirias
force-pushed
the
master
branch
3 times, most recently
from
May 30, 2025 06:31
1ad58a0 to
ba5215a
Compare
Zirias
force-pushed
the
master
branch
14 times, most recently
from
June 3, 2025 14:57
fca9131 to
7aa6332
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: