Skip to content

Commit 620b269

Browse files
bruce-richardsondavid-marchand
authored andcommitted
buildtools/cmdline: support optional parameters
Sometimes a user may want to have a command which takes an optional parameter. For commands with an optional constant string, this is no issue, as it can be configured as two separate commands, e.g. start start tx_first. However, if we want to have a variable parameter on the command, we hit issues, because variable tokens do not form part of the generated command names used for function and result-struct naming. To avoid duplicate name issues, we add a special syntax to allow the user to indicate that a particular variable parameter should be included in the name. Any leading variable names starting with a "__" will be included in command naming. This then allows us to have: start start tx_first start tx_first <UINT16>__n without hitting any naming conflicts. Signed-off-by: Bruce Richardson <[email protected]> Acked-by: Sunil Kumar Kori <[email protected]>
1 parent fb8a278 commit 620b269

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

buildtools/dpdk-cmdline-gen.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ def process_command(lineno, tokens, comment):
4040
name_tokens = []
4141
for t in tokens:
4242
if t.startswith("<"):
43-
break
43+
# stop processing the name building at a variable token,
44+
# UNLESS the token name starts with "__"
45+
t_type, t_name = t[1:].split(">")
46+
if not t_name.startswith("__"):
47+
break
48+
t = t_name[2:] # strip off the leading '__'
4449
name_tokens.append(t)
4550
name = "_".join(name_tokens)
4651

@@ -51,6 +56,8 @@ def process_command(lineno, tokens, comment):
5156
if t.startswith("<"):
5257
t_type, t_name = t[1:].split(">")
5358
t_val = "NULL"
59+
if t_name.startswith("__"):
60+
t_name = t_name[2:]
5461
else:
5562
t_type = "STRING"
5663
t_name = t

doc/guides/prog_guide/cmdline.rst

+13
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ To get at the results structure for each command above,
159159
the ``parsed_result`` parameter should be cast to ``struct cmd_quit_result``
160160
or ``struct cmd_show_port_stats_result`` respectively.
161161

162+
.. note::
163+
164+
In some cases, the user may want to have an optional variable parameter at the end of a command.
165+
Such a variable parameter would not normally be included in the "cmdname" string,
166+
leading to duplicate definition errors.
167+
To work around this,
168+
any variable token with a name prefixed by ``'__'`` will be included in the "cmdname" string,
169+
with the prefix removed.
170+
Using this, it is possible to have commands, such as:
171+
``start tx_first`` and ``start tx_first <UINT16>__n``, without them conflicting.
172+
The resulting code generated will expect functions called ``cmd_start_tx_first_parsed``
173+
and ``cmd_start_tx_first_n_parsed`` respectively.
174+
162175
Integrating with the Application
163176
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164177

0 commit comments

Comments
 (0)