aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-10-07 13:13:07 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2020-10-07 14:17:02 +0700
commit7e1a78fb03fb32ff7e9ea3da0ae1e944a93fffee (patch)
treeef0a51e4e0c5d99b4a0d8ea03b360d69e8b6c2b7
parent9a28d3c599b8be7b1442cce1d8598f48bd99bb86 (diff)
vty/command: assign flags to CMD_ATTR_{IMMEDIATE,NODE_EXIT}
-rw-r--r--src/vty/command.c54
-rw-r--r--tests/vty/vty_transcript_test.vty20
2 files changed, 57 insertions, 17 deletions
diff --git a/src/vty/command.c b/src/vty/command.c
index 60fb6207..d64902ba 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -631,6 +631,19 @@ static const struct value_string cmd_attr_desc[] = {
{ 0, NULL }
};
+/* Get a flag character for a global VTY command attribute */
+static char cmd_attr_get_flag(unsigned int attr)
+{
+ switch (attr) {
+ case CMD_ATTR_IMMEDIATE:
+ return '!';
+ case CMD_ATTR_NODE_EXIT:
+ return '@';
+ default:
+ return '.';
+ }
+}
+
/* Description of attributes shared between the lib commands */
static const char * const cmd_lib_attr_desc[32] = {
/* [OSMO_LIBNAME_LIB_ATTR_ATTRNAME] = \
@@ -662,14 +675,20 @@ static int vty_dump_element(struct cmd_element *cmd, print_func_t print_func, vo
for (i = 0; i < ARRAY_SIZE(cmd_attr_desc) - 1; i++) {
char *xml_att_desc;
+ char flag;
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",
+ print_func(data, " <attribute doc='%s'",
xml_att_desc, newline);
talloc_free(xml_att_desc);
+
+ flag = cmd_attr_get_flag(cmd_attr_desc[i].value);
+ if (flag != '.')
+ print_func(data, " flag='%c'", flag);
+ print_func(data, " />%s", newline);
}
print_func(data, " </attributes>%s", newline);
@@ -2965,9 +2984,12 @@ static void print_attr_list(struct vty *vty, unsigned int attr_mask)
vty_out(vty, " Global attributes:%s", VTY_NEWLINE);
for (i = 0; i < ARRAY_SIZE(cmd_attr_desc) - 1; i++) {
+ flag = cmd_attr_get_flag(cmd_attr_desc[i].value);
desc = cmd_attr_desc[i].str;
- flag = '.'; /* FIXME: no flags defined */
- vty_out(vty, " %c %s%s", flag, desc, VTY_NEWLINE);
+
+ /* Skip attributes without flags */
+ if (flag != '.')
+ vty_out(vty, " %c %s%s", flag, desc, VTY_NEWLINE);
}
}
@@ -3072,7 +3094,26 @@ static unsigned int node_flag_mask(const struct cmd_node *cnode)
return flag_mask;
}
-/* Compose flag char-mask for the given command (e.g. ".F.OB..") */
+/* Compose global flag char-mask for the given command (e.g. "!" or "@") */
+static const char *cmd_gflag_mask(const struct cmd_element *cmd)
+{
+ static char char_mask[8 + 1];
+ char *ptr = &char_mask[0];
+
+ /* Mutually exclusive global attributes */
+ if (cmd->attr & CMD_ATTR_IMMEDIATE)
+ *(ptr++) = cmd_attr_get_flag(CMD_ATTR_IMMEDIATE);
+ else if (cmd->attr & CMD_ATTR_NODE_EXIT)
+ *(ptr++) = cmd_attr_get_flag(CMD_ATTR_NODE_EXIT);
+ else
+ *(ptr++) = '.';
+
+ *ptr = '\0';
+
+ return char_mask;
+}
+
+/* Compose app / lib flag char-mask for the given command (e.g. ".F.OB..") */
static const char *cmd_flag_mask(const struct cmd_element *cmd,
unsigned int flag_mask)
{
@@ -3121,10 +3162,11 @@ gDEFUN(config_list, config_list_cmd,
continue;
if (cmd->attr & (CMD_ATTR_DEPRECATED | CMD_ATTR_HIDDEN))
continue;
- if (!flag_mask)
+ if (!argc)
vty_out(vty, " %s%s", cmd->string, VTY_NEWLINE);
else {
- vty_out(vty, " %s %s%s",
+ vty_out(vty, " %s %s %s%s",
+ cmd_gflag_mask(cmd),
cmd_flag_mask(cmd, flag_mask),
cmd->string, VTY_NEWLINE);
}
diff --git a/tests/vty/vty_transcript_test.vty b/tests/vty/vty_transcript_test.vty
index 28edf29c..b626f3db 100644
--- a/tests/vty/vty_transcript_test.vty
+++ b/tests/vty/vty_transcript_test.vty
@@ -87,10 +87,8 @@ ok argc=0
vty_transcript_test> show vty-attributes
Global attributes:
- . This command is deprecated
- . This command is hidden
- . This command applies immediately
- . This command applies on VTY node exit
+ ! This command applies immediately
+ @ This command applies on VTY node exit
Library specific attributes:
A This command applies on ASP restart
Application specific attributes:
@@ -115,10 +113,10 @@ vty_transcript_test(config-attr-test)# list
vty_transcript_test(config-attr-test)# list with-flags
...
- ... foo-immediate
- ... foo-node-exit
- u.. app-unbelievable
- .m. app-magnificent
- ..w app-wonderful
- um. app-unbelievable-magnificent
- u.w app-unbelievable-wonderful
+ ! ... foo-immediate
+ @ ... foo-node-exit
+ . u.. app-unbelievable
+ . .m. app-magnificent
+ . ..w app-wonderful
+ . um. app-unbelievable-magnificent
+ . u.w app-unbelievable-wonderful