summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorpaul <paul>2003-01-18 00:39:19 +0000
committerpaul <paul>2003-01-18 00:39:19 +0000
commiteda031f6f3558239da5ceb196312ff71aa74fef1 (patch)
tree1c8719ab3e5cbd02166a4e8cc666cf50bdcd09aa /lib/command.c
parentd7ccae28299c5f56cb65135b59e17a68c6b16cd3 (diff)
Finish off merge off CLI extensions, see below for description. Merge should
be off: From havanna_moon@gmx.net Sat Jan 18 00:37:13 2003 Date: Mon, 9 Dec 2002 05:32:58 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: "the list(tm) Zebra" <zebra@zebra.org> Subject: [zebra 16671] [PATCH] CLI extensions. Hi, this patch adds 2 improvements to the CLI (lib/command.c): #1) When in subconfig mode (router XXX, interface XXX, ...) commands that fail for that node are tried on the main CONFIG_NODE. This is great for configuring interfaces or changing the sub-config mode quickly, without the need to type 'exit' between commands: ospfd(config)# int eth1 ospfd(config-if)# ip ospf cost 9 ospfd(config-if)# ip ospf prio 101 ospfd(config-if)# router ospf ospfd(config-router)# network 1.1.1.0/24 area 51 ospfd(config-router)# int eth2 ospfd(config-if)# ip ospf authentication message-digest ospfd(config-if)# ^Z ospfd# Is this IOS-like or does IOS try to walk up the tree of config sub-modes instead of directly trying the command on CONFIG_NODE? CAVEATS: "?" and "TAB" don't work. IIRC IOS doesnt show that help neither. NON-CAVEATS: This wont break much, as config_from_file() already does try a failed command on the parent node of the actual vty->node. If changing the code to walk the node tree instead of directly trying the command on the ENABLE_NODE the same semantics would be in use and no future bugs could creep in. #2) When in config or subconfig mode use the "do " prefix to execute commans of the ENABLE_NODE. "?" and "TAB" work. The space after the "do" is needed: ospfd(config-router)# do<?> % There is no matched command. ospfd(config-router)# do <?> clear Reset functions configure Configuration from vty interface copy Copy configuration debug Debugging functions (see also 'undebug') disable Turn off privileged mode command end End current mode and change to enable mode. exit Exit current mode and down to previous mode help Description of the interactive help system list Print command list no Negate a command or set its defaults quit Exit current mode and down to previous mode show Show running system information terminal Set terminal line parameters who Display who is on vty write Write running configuration to memory, network, or terminal ospfd(config-router)# do sho<TAB> ospfd(config-router)# do show me<TAB> ospfd(config-router)# do show memory r<TAB> ospfd(config-router)# do show memory rip RIP structure : 0 RIP route info : 0 RIP interface : 0 RIP peer : 0 RIP offset list : 0 RIP distance : 0 ospfd(config-router)# ^Z ospfd# CAVEATS: I don't have access to an IOS with this feature, so I implemented it from the comments on this mailing list (in fact my personal motivation was to implement feature #1, which I missed on zebra. But #2 sounded like a nice one to have, and xemacs was already parked on command.c ...). Is this IOS-like or are there differences? I will happily change this patch to mimick IOS or the mailing-list consensus on CLI-usability. regards, yon
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c89
1 files changed, 88 insertions, 1 deletions
diff --git a/lib/command.c b/lib/command.c
index 8fd2b648..f0ddb6d7 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1582,6 +1582,40 @@ cmd_describe_command (vector vline, struct vty *vty, int *status)
}
+vector
+cmd_describe_command (vector vline, struct vty *vty, int *status)
+{
+ vector ret;
+
+ if ( cmd_try_do_shortcut(vty->node, vector_slot(vline, 0) ) )
+ {
+ enum node_type onode;
+ vector shifted_vline;
+ int index;
+
+ onode = vty->node;
+ vty->node = ENABLE_NODE;
+ /* We can try it on enable node, cos' the vty is authenticated */
+
+ shifted_vline = vector_init (vector_count(vline));
+ /* use memcpy? */
+ for (index = 1; index < vector_max (vline); index++)
+ {
+ vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
+ }
+
+ ret = cmd_describe_command_real (shifted_vline, vty, status);
+
+ vector_free(shifted_vline);
+ vty->node = onode;
+ return ret;
+ }
+
+
+ return cmd_describe_command_real (vline, vty, status);
+}
+
+
/* Check LCD of matched command. */
int
cmd_lcd (char **matched)
@@ -1764,7 +1798,7 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status)
}
char **
-cmd_complete_command (vector vline, struct vty *vty, int *status)
+cmd_complete_command_real (vector vline, struct vty *vty, int *status)
{
char **ret;
@@ -1991,6 +2025,59 @@ cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd) {
return ret;
}
+
+int
+cmd_execute_command (vector vline, struct vty *vty, struct cmd_element **cmd) {
+ int ret;
+ enum node_type onode = vty->node;
+
+ if ( cmd_try_do_shortcut(vty->node, vector_slot(vline, 0) ) )
+ {
+ vector shifted_vline;
+ int index;
+
+ vty->node = ENABLE_NODE;
+ /* We can try it on enable node, cos' the vty is authenticated */
+
+ shifted_vline = vector_init (vector_count(vline));
+ /* use memcpy? */
+ for (index = 1; index < vector_max (vline); index++)
+ {
+ vector_set_index (shifted_vline, index-1, vector_lookup(vline, index));
+ }
+
+ ret = cmd_execute_command_real (shifted_vline, vty, cmd);
+
+ vector_free(shifted_vline);
+ vty->node = onode;
+ return ret;
+ }
+
+
+ ret = cmd_execute_command_real (vline, vty, cmd);
+
+ /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */
+ if ( ret != CMD_SUCCESS && ret != CMD_WARNING
+ && vty->node > CONFIG_NODE )
+ {
+ /* XXX try node_parent(vty->node)? */
+ vty->node = CONFIG_NODE;
+ ret = cmd_execute_command_real (vline, vty, cmd);
+ if (ret != CMD_SUCCESS && ret != CMD_WARNING)
+ {
+ /* if the command changed the node dont reset it */
+ if( vty->node == CONFIG_NODE )
+ vty->node = onode;
+ return ret;
+ }
+ else
+ if( vty->node == CONFIG_NODE )
+ vty->node = onode;
+ /* if the command changed the node dont reset it */
+ }
+ return ret;
+}
+
/* Execute command by argument readline. */
int
cmd_execute_command_strict (vector vline, struct vty *vty,