summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-01-31 08:13:31 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2019-02-04 16:43:57 +0000
commitb55f4d2df21b966c3953264d8961f259814f4650 (patch)
tree6347e1da541fc51cfedf2c896b5ad751f1fcbaec /tests
parentc197809deb6add8b69a5460a91436b80be218d31 (diff)
vty: enable optional-multi-choice syntax: [(one|two)]
Since very recently we sensibly handle commands like cmd ([one]|[two]|[three]) as optional multi-choice arguments. In addition, support the more obvious syntax of cmd [(one|two|three)] Internally, the tokens are mangled to [one] [two] and [three], which is how the rest of the code detects optional args, and makes sense in terms of UI: > cmd ? [one] [two] [three] (i.e. optional arguments are always shown in braces in '?' listings) Before this patch, commands defined with a syntax like [(one|two)], would lead to an assertion (shows as "multiple") during program startup. Change-Id: I952b3c00f97e2447f2308b0ec6f5f1714692b5b2
Diffstat (limited to 'tests')
-rw-r--r--tests/vty/vty_transcript_test.c9
-rw-r--r--tests/vty/vty_transcript_test.vty15
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/vty/vty_transcript_test.c b/tests/vty/vty_transcript_test.c
index 50131ea9..7ffe713a 100644
--- a/tests/vty/vty_transcript_test.c
+++ b/tests/vty/vty_transcript_test.c
@@ -170,10 +170,19 @@ DEFUN(multi1, multi1_cmd,
return CMD_SUCCESS;
}
+DEFUN(multi2, multi2_cmd,
+ "multi2 [(one|two|three)]",
+ "multi2 test command\n" "1\n2\n3\n")
+{
+ vty_out(vty, "ok argc=%d%s%s%s", argc, argc ? " " : "", argc ? argv[0] : "", VTY_NEWLINE);
+ return CMD_SUCCESS;
+}
+
static void init_vty_cmds()
{
install_element_ve(&multi0_cmd);
install_element_ve(&multi1_cmd);
+ install_element_ve(&multi2_cmd);
}
int main(int argc, char **argv)
diff --git a/tests/vty/vty_transcript_test.vty b/tests/vty/vty_transcript_test.vty
index 514a5ed7..57920a85 100644
--- a/tests/vty/vty_transcript_test.vty
+++ b/tests/vty/vty_transcript_test.vty
@@ -2,6 +2,7 @@ vty_transcript_test> list
...
multi0 (one|two|three)
multi1 ([one]|[two]|[three])
+ multi2 [(one|two|three)]
vty_transcript_test> multi0 ?
one 1
@@ -51,3 +52,17 @@ ok argc=0
vty_transcript_test> multi1 [one]
% Unknown command.
+
+vty_transcript_test> multi2 ?
+ [one] 1
+ [two] 2
+ [three] 3
+
+vty_transcript_test> multi2 one
+ok argc=1 one
+
+vty_transcript_test> multi2 two
+ok argc=1 two
+
+vty_transcript_test> multi2
+ok argc=0