Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions config_utilities/app/composite_configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Invalid YAML or missing files get dropped during compositing.
multiple times.
-d/--disable-substitutions: Turn off substitutions resolution
--no-disable-substitutions: Turn substitution resolution on (currently on by default)
--force-block-style: Force emitted YAML to only use block style

Example:
> echo "{a: 42, bar: hello}" > /tmp/test_in.yaml
Expand Down Expand Up @@ -87,6 +88,32 @@ inline void forceBlockForNonLeaves(YAML::Node node) {
}
}

inline void forceBlockForAll(YAML::Node node) {
switch (node.Type()) {
case YAML::NodeType::Sequence:
if (node.size() > 0) {
node.SetStyle(YAML::EmitterStyle::Block);
}
for (const auto& child : node) {
forceBlockForAll(child);
}
break;
case YAML::NodeType::Map:
if (node.size() > 0) {
node.SetStyle(YAML::EmitterStyle::Block);
}
for (const auto& child : node) {
forceBlockForAll(child.second);
}
break;
case YAML::NodeType::Null:
case YAML::NodeType::Undefined:
case YAML::NodeType::Scalar:
default:
return;
}
}

} // namespace

int main(int argc, char* argv[]) {
Expand All @@ -98,6 +125,9 @@ int main(int argc, char* argv[]) {
}

forceBlockForNonLeaves(result);
if (info.force_block_style) {
forceBlockForAll(result);
}

YAML::Emitter emit;
switch (result.Type()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace internal {

struct ParserInfo {
bool help_present = false;
bool force_block_style = false;
};

/**
Expand Down
7 changes: 7 additions & 0 deletions config_utilities/src/commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ CliParser& CliParser::parse(int& argc, char* argv[], bool remove_args) {
continue;
}

if ((curr_opt == "--force-block-style") && !found_separator) {
info.force_block_style = true;
spans.emplace_back(Span{i, 0, curr_opt});
++i;
continue;
}

if (curr_opt == "--" && !found_separator) {
found_separator = true;
spans.emplace_back(Span{i, 0, curr_opt});
Expand Down