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/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgNeels Hofmeyr has submitted this change and it was merged. ( https://gerrit.osmocom.org/12769 )
Change subject: vty: enable optional-multi-choice syntax: ([one]|[two])
......................................................................
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
---
M src/vty/command.c
M tests/vty/vty_transcript_test.vty
2 files changed, 2 insertions(+), 2 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 a540cd5..9d02d69 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -467,7 +467,7 @@
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;
diff --git a/tests/vty/vty_transcript_test.vty b/tests/vty/vty_transcript_test.vty
index 1ae7c0d..514a5ed 100644
--- a/tests/vty/vty_transcript_test.vty
+++ b/tests/vty/vty_transcript_test.vty
@@ -47,7 +47,7 @@
ok argc=1 th
vty_transcript_test> multi1
-% Command incomplete.
+ok argc=0
vty_transcript_test> multi1 [one]
% Unknown command.
--
To view, visit https://gerrit.osmocom.org/12769
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I9a8474bd89ddc2155c58bfca7bd038d586aaa60a
Gerrit-Change-Number: 12769
Gerrit-PatchSet: 3
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190204/2869a635/attachment.htm>