[v5,8/9] buildtools/dpdk-cmdline-gen: support option strings

Message ID 20231017121318.146007-9-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series document and simplify use of cmdline |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Oct. 17, 2023, 12:13 p.m. UTC
  Add support to the commandline generator for option strings, where there
are only a limited number of acceptable values to be passed as a
parameter.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 buildtools/dpdk-cmdline-gen.py    | 7 +++++++
 doc/guides/prog_guide/cmdline.rst | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
  

Patch

diff --git a/buildtools/dpdk-cmdline-gen.py b/buildtools/dpdk-cmdline-gen.py
index 6cb7610de4..fe74194121 100755
--- a/buildtools/dpdk-cmdline-gen.py
+++ b/buildtools/dpdk-cmdline-gen.py
@@ -73,6 +73,13 @@  def process_command(lineno, tokens, comment):
                 f"cmdline_parse_token_ipaddr_t cmd_{name}_{t_name}_tok =\n"
                 + f"\tTOKEN_IPV4_INITIALIZER(struct cmd_{name}_result, {t_name});"
             )
+        elif t_type.startswith("|") and t_type.endswith("|"):
+            result_struct.append(f"\tcmdline_fixed_string_t {t_name};")
+            t_val = f'"{t_type[1:-1].replace("|","#")}"'
+            initializers.append(
+                f"static cmdline_parse_token_string_t cmd_{name}_{t_name}_tok =\n"
+                + f"\tTOKEN_STRING_INITIALIZER(struct cmd_{name}_result, {t_name}, {t_val});"
+            )
         else:
             raise TypeError(f"Error line {lineno + 1}: unknown token type '{t_type}'")
         token_list.append(f"cmd_{name}_{t_name}_tok")
diff --git a/doc/guides/prog_guide/cmdline.rst b/doc/guides/prog_guide/cmdline.rst
index 0b96b770e2..1268eca911 100644
--- a/doc/guides/prog_guide/cmdline.rst
+++ b/doc/guides/prog_guide/cmdline.rst
@@ -62,7 +62,8 @@  The format of the list file must be:
 
 * One command per line
 
-* Variable fields are prefixed by the type-name in angle-brackets, for example:
+* Variable fields are prefixed by the type-name, or "|"-delimited option-list, in angle-brackets.
+  For example:
 
   * ``<STRING>message``
 
@@ -70,6 +71,8 @@  The format of the list file must be:
 
   * ``<IP>src_ip``
 
+  * ``<|rx|tx|rxtx|>mode``
+
 * The help text for a command is given in the form of a comment on the same line as the command
 
 An example list file, with a variety of (unrelated) commands, is shown below::
@@ -79,6 +82,7 @@  An example list file, with a variety of (unrelated) commands, is shown below::
    add <UINT16>x <UINT16>y  # add x and y
    echo <STRING>message     # print message to screen
    add socket <STRING>path  # add unix socket with the given path
+   set mode <|rx|tx|>rxtx   # set Rx-only or Tx-only mode
    quit                     # close the application
 
 Running the Generator Script