aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-09-28 13:03:49 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-09-28 13:03:52 +0700
commit7f6c87da2f5a78a76c3bc019d31c6473f3eb9487 (patch)
tree46a38525e5ffadc7f59ebbc23a3eb527fc4f270f
parent4a96b7c7b9d9987afa7493f0b9b48ada8ae058ef (diff)
vty/command: reflect global attributes in the XML reference
Given that commands with either/both of the following attributes: - CMD_ATTR_DEPRECATED, - CMD_ATTR_HIDDEN, never end up in the XML reference, only CMD_ATTR_IMMEDIATE would be reflected for commands taking effect immediately as follows: <command id='foo'> <!-- Global attributes --> <attributes scope='global'> <attribute doc='This command applies immediately' /> </attributes> <!-- Application specific attributes --> <attributes scope='application'> <!-- ... --> </attributes> <params> <!-- ... --> </params> </command> Change-Id: I8476c1163c23a9a52641987acf3df0b8c49d8f7b Related: SYS#4937
-rw-r--r--src/vty/command.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/vty/command.c b/src/vty/command.c
index bad26888..30c39a72 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -622,6 +622,13 @@ static char *xml_escape(const char *inp)
typedef int (*print_func_t)(void *data, const char *fmt, ...);
+static const struct value_string cmd_attr_desc[] = {
+ { CMD_ATTR_DEPRECATED, "This command is deprecated" },
+ { CMD_ATTR_HIDDEN, "This command is hidden" },
+ { CMD_ATTR_IMMEDIATE, "This command applies immediately" },
+ { 0, NULL }
+};
+
/*
* Write one cmd_element as XML via a print_func_t.
*/
@@ -632,6 +639,25 @@ static int vty_dump_element(struct cmd_element *cmd, print_func_t print_func, vo
print_func(data, " <command id='%s'>%s", xml_string, newline);
+ /* Print global attributes and their description */
+ if (cmd->attr != 0x00) { /* ... if at least one flag is set */
+ print_func(data, " <attributes scope='global'>%s", newline);
+
+ for (i = 0; i < ARRAY_SIZE(cmd_attr_desc) - 1; i++) {
+ char *xml_att_desc;
+
+ if (~cmd->attr & cmd_attr_desc[i].value)
+ continue;
+
+ xml_att_desc = xml_escape(cmd_attr_desc[i].str);
+ print_func(data, " <attribute doc='%s' />%s",
+ xml_att_desc, newline);
+ talloc_free(xml_att_desc);
+ }
+
+ print_func(data, " </attributes>%s", newline);
+ }
+
/* Print application specific attributes and their description */
if (cmd->usrattr != 0x00) { /* ... if at least one flag is set */
print_func(data, " <attributes scope='application'>%s", newline);