Change in libosmocore[master]: vty/command: introduce a command to list attributes

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/.

fixeria gerrit-no-reply at lists.osmocom.org
Mon Oct 5 17:23:41 UTC 2020


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20459 )


Change subject: vty/command: introduce a command to list attributes
......................................................................

vty/command: introduce a command to list attributes

Change-Id: I561114d7416e30cc06b7d49c0bc1217a76039c99
Related: SYS#4937
---
M src/vty/command.c
1 file changed, 88 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/59/20459/1

diff --git a/src/vty/command.c b/src/vty/command.c
index 7752c91..f35be81 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -2963,6 +2963,91 @@
 	return CMD_SUCCESS;
 }
 
+enum {
+	ATTR_TYPE_GLOBAL	= (1 << 0),
+	ATTR_TYPE_LIB		= (1 << 1),
+	ATTR_TYPE_APP		= (1 << 2),
+};
+
+static void print_attr_list(struct vty *vty, unsigned int attr_mask)
+{
+	const char *desc;
+	unsigned int i;
+	bool found;
+	char flag;
+
+	if (attr_mask & ATTR_TYPE_GLOBAL) {
+		vty_out(vty, "  Global attributes:%s", VTY_NEWLINE);
+
+		for (i = 0; i < ARRAY_SIZE(cmd_attr_desc) - 1; i++) {
+			desc = cmd_attr_desc[i].str;
+			flag = '.'; /* FIXME: no flags defined */
+			vty_out(vty, "    %c  %s%s", flag, desc, VTY_NEWLINE);
+		}
+	}
+
+	if (attr_mask & ATTR_TYPE_LIB) {
+		vty_out(vty, "  Library specific attributes:%s", VTY_NEWLINE);
+
+		for (i = 0, found = false; i < _OSMO_CORE_LIB_ATTR_COUNT; i++) {
+			if ((desc = cmd_lib_attr_desc[i]) == NULL)
+				continue;
+			found = true;
+
+			flag = cmd_lib_attr_letters[i];
+			if (flag == '\0')
+				flag = '.';
+
+			vty_out(vty, "    %c  %s%s", flag, desc, VTY_NEWLINE);
+		}
+
+		if (!found)
+			vty_out(vty, "    (no attributes)%s", VTY_NEWLINE);
+	}
+
+	if (attr_mask & ATTR_TYPE_APP) {
+		vty_out(vty, "  Application specific attributes:%s", VTY_NEWLINE);
+
+		for (i = 0, found = false; i < ARRAY_SIZE(host.app_info->usr_attr_desc); i++) {
+			if ((desc = host.app_info->usr_attr_desc[i]) == NULL)
+				continue;
+			found = true;
+
+			flag = host.app_info->usr_attr_letters[i];
+			if (flag == '\0')
+				flag = '.';
+
+			vty_out(vty, "    %c  %s%s", flag, desc, VTY_NEWLINE);
+		}
+
+		if (!found)
+			vty_out(vty, "    (no attributes)%s", VTY_NEWLINE);
+	}
+}
+
+gDEFUN(list_attr, list_attr_cmd,
+       "list-attributes (all|application|library|global)",
+       "Print list of attributes\n"
+       "All attributes\n"
+       "Application specific attributes only\n"
+       "Library specific attributes only\n"
+       "Global attributes only\n")
+{
+	unsigned int attr_mask = 0;
+
+	if (argv[0][0] == 'g') /* global */
+		attr_mask |= ATTR_TYPE_GLOBAL;
+	else if (argv[0][0] == 'l') /* library */
+		attr_mask |= ATTR_TYPE_LIB;
+	else if (argv[0][1] == 'p') /* application */
+		attr_mask |= ATTR_TYPE_APP;
+	else if (argv[0][1] == 'l') /* all */
+		attr_mask = 0xff;
+
+	print_attr_list(vty, attr_mask);
+	return CMD_SUCCESS;
+}
+
 static int write_config_file(const char *config_file, char **outpath)
 {
 	unsigned int i;
@@ -3928,6 +4013,7 @@
 {
 	install_lib_element(node, &config_help_cmd);
 	install_lib_element(node, &config_list_cmd);
+	install_lib_element(node, &list_attr_cmd);
 
 	install_lib_element(node, &config_write_terminal_cmd);
 	install_lib_element(node, &config_write_file_cmd);
@@ -3950,6 +4036,7 @@
 {
 	if (cmd == &config_help_cmd
 	    || cmd == &config_list_cmd
+	    || cmd == &list_attr_cmd
 	    || cmd == &config_write_terminal_cmd
 	    || cmd == &config_write_file_cmd
 	    || cmd == &config_write_memory_cmd
@@ -4030,6 +4117,7 @@
 	install_lib_element(VIEW_NODE, &show_online_help_cmd);
 	if (terminal) {
 		install_lib_element(VIEW_NODE, &config_list_cmd);
+		install_lib_element(VIEW_NODE, &list_attr_cmd);
 		install_lib_element(VIEW_NODE, &config_exit_cmd);
 		install_lib_element(VIEW_NODE, &config_help_cmd);
 		install_lib_element(VIEW_NODE, &config_enable_cmd);

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/20459
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I561114d7416e30cc06b7d49c0bc1217a76039c99
Gerrit-Change-Number: 20459
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201005/c39c42f3/attachment.htm>


More information about the gerrit-log mailing list