This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/20471 )
Change subject: vty/command: assign flags to CMD_ATTR_{IMMEDIATE,NODE_EXIT}
......................................................................
vty/command: assign flags to CMD_ATTR_{IMMEDIATE,NODE_EXIT}
Change-Id: I77c1ef7ca4c667c769cc53c7ac65c3be5c7e1c86
Related: SYS#4937
---
M src/vty/command.c
M tests/vty/vty_transcript_test.vty
2 files changed, 57 insertions(+), 17 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/src/vty/command.c b/src/vty/command.c
index 60fb620..d64902b 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -631,6 +631,19 @@
{ 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 @@
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 @@
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 @@
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 @@
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 28edf29..b626f3d 100644
--- a/tests/vty/vty_transcript_test.vty
+++ b/tests/vty/vty_transcript_test.vty
@@ -87,10 +87,8 @@
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 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
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/20471
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I77c1ef7ca4c667c769cc53c7ac65c3be5c7e1c86
Gerrit-Change-Number: 20471
Gerrit-PatchSet: 2
Gerrit-Owner: Vadim Yanitskiy <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201007/267a86ec/attachment.htm>