<p>Neels Hofmeyr <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/12769">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty: enable optional-multi-choice syntax: ([one]|[two])<br><br>Add basic optional multi-choice argument support.<br><br>The VTY detects optional arguments by square braces.<br><br> > cmd ?<br> [optional-arg]<br> > cmd optional-arg<br> ok<br> > cmd<br> ok<br><br>However, within multi-choice args, these braces were so far not treated as<br>optional:<br><br> > list<br> cmd2 ([one]|[two]|[three])<br> > cmd2<br> % Command incomplete<br><br>In preparation for I952b3c00f97e2447f2308b0ec6f5f1714692b5b2 which will enable<br>the more obvious syntax of<br><br>  cmd [(one|two)]<br><br>for reasons of internal implementation, first support a syntax of<br><br>  cmd ([one]|[two])<br><br>The internal vty implementation always needs square braces around each option.<br>There is currently no good way to prevent developers from defining braces<br>inside multi-arguments, so it is easiest to allow and handle them:<br><br> > list<br> cmd2 ([one]|[two]|[three])<br> > cmd2<br> ok<br><br>The VTY doesn't guard against a mix like<br><br> cmd (one|[two])<br><br>With this patch, a multi-choice command is treated as optional iff the first<br>element is in square brackets. The remaining elements' square brackets have no<br>effect besides confusing the user. This is not explicitly checked against.<br><br>In general, I would prefer to check all of these details, but the current VTY<br>code with its endless code duplication and obscure string mangling just doesn't<br>provide that luxury. There are numerous worse errors hidden in there.<br><br>Change-Id: I9a8474bd89ddc2155c58bfca7bd038d586aaa60a<br>---<br>M src/vty/command.c<br>M tests/vty/vty_transcript_test.vty<br>2 files changed, 2 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/vty/command.c b/src/vty/command.c</span><br><span>index a540cd5..9d02d69 100644</span><br><span>--- a/src/vty/command.c</span><br><span>+++ b/src/vty/command.c</span><br><span>@@ -467,7 +467,7 @@</span><br><span> </span><br><span>   for (i = 0; i < vector_active(strvec); i++)</span><br><span>               if ((descvec = vector_slot(strvec, i)) != NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">-                       if ((vector_active(descvec)) == 1</span><br><span style="color: hsl(120, 100%, 40%);">+                     if ((vector_active(descvec)) >= 1</span><br><span>                             && (desc = vector_slot(descvec, 0)) != NULL) {</span><br><span>                           if (desc->cmd == NULL || CMD_OPTION(desc->cmd))</span><br><span>                                        return size;</span><br><span>diff --git a/tests/vty/vty_transcript_test.vty b/tests/vty/vty_transcript_test.vty</span><br><span>index 1ae7c0d..514a5ed 100644</span><br><span>--- a/tests/vty/vty_transcript_test.vty</span><br><span>+++ b/tests/vty/vty_transcript_test.vty</span><br><span>@@ -47,7 +47,7 @@</span><br><span> ok argc=1 th</span><br><span> </span><br><span> vty_transcript_test> multi1</span><br><span style="color: hsl(0, 100%, 40%);">-% Command incomplete.</span><br><span style="color: hsl(120, 100%, 40%);">+ok argc=0</span><br><span> </span><br><span> vty_transcript_test> multi1 [one]</span><br><span> % Unknown command.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/12769">change 12769</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/12769"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I9a8474bd89ddc2155c58bfca7bd038d586aaa60a </div>
<div style="display:none"> Gerrit-Change-Number: 12769 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Neels Hofmeyr <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr@sysmocom.de> </div>