summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-01-31 08:14:26 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2019-02-04 16:43:57 +0000
commitc197809deb6add8b69a5460a91436b80be218d31 (patch)
treef8d527e204c02002078f1ccec3386adbafa726cb /src
parentfaa49e24cb8044134a6c0d5621ca298cae628c4e (diff)
vty: enable optional-multi-choice syntax: ([one]|[two])
Add basic optional multi-choice argument support. The VTY detects optional arguments by square braces. > cmd ? [optional-arg] > cmd optional-arg ok > cmd ok However, within multi-choice args, these braces were so far not treated as optional: > list cmd2 ([one]|[two]|[three]) > cmd2 % Command incomplete In preparation for I952b3c00f97e2447f2308b0ec6f5f1714692b5b2 which will enable the more obvious syntax of cmd [(one|two)] for reasons of internal implementation, first support a syntax of cmd ([one]|[two]) The internal vty implementation always needs square braces around each option. There is currently no good way to prevent developers from defining braces inside multi-arguments, so it is easiest to allow and handle them: > list cmd2 ([one]|[two]|[three]) > cmd2 ok The VTY doesn't guard against a mix like cmd (one|[two]) With this patch, a multi-choice command is treated as optional iff the first element is in square brackets. The remaining elements' square brackets have no effect besides confusing the user. This is not explicitly checked against. In general, I would prefer to check all of these details, but the current VTY code with its endless code duplication and obscure string mangling just doesn't provide that luxury. There are numerous worse errors hidden in there. Change-Id: I9a8474bd89ddc2155c58bfca7bd038d586aaa60a
Diffstat (limited to 'src')
-rw-r--r--src/vty/command.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/vty/command.c b/src/vty/command.c
index a540cd5b..9d02d696 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -467,7 +467,7 @@ static int cmd_cmdsize(vector strvec)
for (i = 0; i < vector_active(strvec); i++)
if ((descvec = vector_slot(strvec, i)) != NULL) {
- if ((vector_active(descvec)) == 1
+ if ((vector_active(descvec)) >= 1
&& (desc = vector_slot(descvec, 0)) != NULL) {
if (desc->cmd == NULL || CMD_OPTION(desc->cmd))
return size;