Add canonical JSON --show-config export and JsonConfigFormatter#165
Open
VolkerChristian wants to merge 5 commits into
Open
Add canonical JSON --show-config export and JsonConfigFormatter#165VolkerChristian wants to merge 5 commits into
VolkerChristian wants to merge 5 commits into
Conversation
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.
Motivation
--show-config=json, emitted directly from the live CLI11/SNode.C configuration tree.-s, bare--show-config, and--show-config=ini.snodec-control, while keeping the existing config-file workflow unchanged.Description
Added
utils::JsonWriterinsrc/utils/JsonWriter.{h,cpp}as a small deterministic JSON writer with proper string escaping.Added
utils::ConfigJsonFormatterinsrc/utils/ConfigJsonFormatter.{h,cpp}to serialize the live CLI11/SNode.C app tree into a canonical JSON document.Preserved legacy behavior:
-semits INI--show-configemits INI--show-config=iniemits INIAdded explicit JSON export:
--show-config=jsonThe JSON document uses:
format.name = "snodec.config"format.version = 1format.scope = "configurable-options-only"The JSON tree preserves generic CLI11/SNode.C hierarchy. It does not hard-code
Application -> Instances -> Sections; common node kinds such asinstanceandsectionare inferred from CLI11 group names and marked with source metadata.Option groups are emitted as structured JSON objects instead of INI comment headers.
Option values separate semantic values from INI/config-file literals:
configured,effective, andapiDefaultare semantic valuesconfiguredLiteral,effectiveLiteral, andapiDefaultLiteralpreserve config-file literal representationValue-state flags were made explicit:
isEffectiveDefaultisExplicitlyConfiguredisMissingRequiredAnonymous / empty-name CLI11 subcommands are preserved with deterministic generated path segments such as
<anonymous-0>, so every node and option receives a stable non-empty JSONid.JSON stdout purity is preserved for successful
--show-config=json; diagnostics for JSON export failures are written to stderr.Added
docs/config-json.mddocumenting the schema, compatibility behavior, value semantics, heuristic metadata, anonymous node IDs, output-purity contract, and known limitations.Updated landing-page documentation to mention the canonical JSON configuration export.
Testing
Added and ran unit coverage in
ConfigJsonFormatterTest, including:JSON writer string escaping:
0x20exact expected JSON output for a small deterministic config tree
canonical format metadata and
configurable-options-onlyscopeapplication metadata and root tree emission
arbitrary nested child nodes
option group preservation
exclusion of non-configurable options
semantic configured/effective values without INI quoting
explicit INI/config-file literal value fields
isEffectiveDefault,isExplicitlyConfigured, andisMissingRequiredrequired placeholder handling
needs/excludesrelation outputanonymous subcommand ID generation
compatibility behavior:
-sdefaults to INI--show-configdefaults to INI--show-config=iniselects INI--show-config=jsonselects JSON--show-config=xmlare rejectedManual validation commands used included:
Known limitations
command-line-or-config.nullfor flattened dotted keys.type.itemsand the literal fields when round-tripping.