[MERGED] libosmocore[master]: vty XML export: avoid repeating common node commands for eac...

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

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Dec 10 13:34:38 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: vty XML export: avoid repeating common node commands for each node
......................................................................


vty XML export: avoid repeating common node commands for each node

We use 'show online-help' to generate VTY reference manuals. It is not helpful
to include the common node commands on each and every node level, it clutters
the actual useful help.

Have a separate first section called 'Common Commands', but omit them
elsewhere.

Change-Id: Ie802eccad80887968b10269ff9c0e9797268e0d4
---
M src/vty/command.c
1 file changed, 45 insertions(+), 0 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/vty/command.c b/src/vty/command.c
index 5f7a42c..e5efad2 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -645,6 +645,8 @@
 	return 0;
 }
 
+static bool vty_command_is_common(struct cmd_element *cmd);
+
 /*
  * Dump all nodes and commands associated with a given node as XML to the VTY.
  */
@@ -654,6 +656,29 @@
 	int same_name_count;
 
 	vty_out(vty, "<vtydoc xmlns='urn:osmocom:xml:libosmocore:vty:doc:1.0'>%s", VTY_NEWLINE);
+
+	/* Only once, list all common node commands. Use the CONFIG node to find common node commands. */
+	vty_out(vty, "  <node id='_common_cmds_'>%s", VTY_NEWLINE);
+	vty_out(vty, "    <name>Common Commands</name>%s", VTY_NEWLINE);
+	vty_out(vty, "    <description>These commands are available on all VTY nodes. They are listed"
+		" here only once, to unclutter the VTY reference.</description>%s", VTY_NEWLINE);
+	for (i = 0; i < vector_active(cmdvec); ++i) {
+		struct cmd_node *cnode;
+		cnode = vector_slot(cmdvec, i);
+		if (!cnode)
+			continue;
+		if (cnode->node != CONFIG_NODE)
+			continue;
+
+		for (j = 0; j < vector_active(cnode->cmd_vector); ++j) {
+			struct cmd_element *elem;
+			elem = vector_slot(cnode->cmd_vector, j);
+			if (!vty_command_is_common(elem))
+				continue;
+			vty_dump_element(elem, vty);
+		}
+	}
+	vty_out(vty, "  </node>%s", VTY_NEWLINE);
 
 	for (i = 0; i < vector_active(cmdvec); ++i) {
 		struct cmd_node *cnode;
@@ -682,6 +707,8 @@
 		for (j = 0; j < vector_active(cnode->cmd_vector); ++j) {
 			struct cmd_element *elem;
 			elem = vector_slot(cnode->cmd_vector, j);
+			if (vty_command_is_common(elem))
+				continue;
 			vty_dump_element(elem, vty);
 		}
 
@@ -3648,6 +3675,24 @@
 	}
 }
 
+/*! Return true if a node is installed by install_basic_node_commands(), so
+ * that we can avoid repeating them for each and every node during 'show
+ * running-config' */
+static bool vty_command_is_common(struct cmd_element *cmd)
+{
+	if (cmd == &config_help_cmd
+	    || cmd == &config_list_cmd
+	    || cmd == &config_write_terminal_cmd
+	    || cmd == &config_write_file_cmd
+	    || cmd == &config_write_memory_cmd
+	    || cmd == &config_write_cmd
+	    || cmd == &show_running_config_cmd
+	    || cmd == &config_exit_cmd
+	    || cmd == &config_end_cmd)
+		return true;
+	return false;
+}
+
 /**
  * Write the current running config to a given file
  * \param[in] vty the vty of the code

-- 
To view, visit https://gerrit.osmocom.org/5246
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie802eccad80887968b10269ff9c0e9797268e0d4
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list