yaml-writer: add ability to enable/disable type annotations

This commit is contained in:
Ariadne Conill 2020-11-13 21:31:48 -07:00
parent 3bf406bf92
commit dd8064142c
3 changed files with 8 additions and 8 deletions

View file

@ -111,7 +111,7 @@ prettyprint_interface_yaml(struct lif_interface *iface)
lif_yaml_node_append_child(iface_node, iface_entry_node); lif_yaml_node_append_child(iface_node, iface_entry_node);
} }
lif_yaml_write(iface_node, stdout); lif_yaml_write(iface_node, stdout, true);
lif_yaml_node_free(&doc); lif_yaml_node_free(&doc);
} }
#endif #endif

View file

@ -22,7 +22,7 @@
static const size_t INDENT_WIDTH = 2; static const size_t INDENT_WIDTH = 2;
static void static void
lif_yaml_write_node(struct lif_yaml_node *node, FILE *f, size_t indent) lif_yaml_write_node(struct lif_yaml_node *node, FILE *f, size_t indent, bool type_annotations)
{ {
struct lif_node *iter; struct lif_node *iter;
@ -34,10 +34,10 @@ lif_yaml_write_node(struct lif_yaml_node *node, FILE *f, size_t indent)
switch (node->value_type) switch (node->value_type)
{ {
case LIF_YAML_BOOLEAN: case LIF_YAML_BOOLEAN:
fprintf(f, "!!bool %s\n", node->value.bool_value ? "true" : "false"); fprintf(f, "%s%s\n", type_annotations ? "!!bool " : "", node->value.bool_value ? "true" : "false");
break; break;
case LIF_YAML_STRING: case LIF_YAML_STRING:
fprintf(f, "!!str %s\n", node->value.str_value); fprintf(f, "%s%s\n", type_annotations ? "!!str " : "", node->value.str_value);
break; break;
case LIF_YAML_OBJECT: case LIF_YAML_OBJECT:
fprintf(f, "\n"); fprintf(f, "\n");
@ -55,12 +55,12 @@ lif_yaml_write_node(struct lif_yaml_node *node, FILE *f, size_t indent)
if (node->value_type == LIF_YAML_LIST) if (node->value_type == LIF_YAML_LIST)
fprintf(f, "%*s-\n", (int) (child_indent - INDENT_WIDTH), ""); fprintf(f, "%*s-\n", (int) (child_indent - INDENT_WIDTH), "");
lif_yaml_write_node(iter_node, f, child_indent); lif_yaml_write_node(iter_node, f, child_indent, type_annotations);
} }
} }
void void
lif_yaml_write(struct lif_yaml_node *doc, FILE *f) lif_yaml_write(struct lif_yaml_node *doc, FILE *f, bool type_annotations)
{ {
lif_yaml_write_node(doc, f, 0); lif_yaml_write_node(doc, f, 0, type_annotations);
} }

View file

@ -19,6 +19,6 @@
#include "libifupdown/libifupdown.h" #include "libifupdown/libifupdown.h"
#include "libifupdown/yaml-base.h" #include "libifupdown/yaml-base.h"
extern void lif_yaml_write(struct lif_yaml_node *doc, FILE *f); extern void lif_yaml_write(struct lif_yaml_node *doc, FILE *f, bool type_annotations);
#endif #endif