diff mbox series

[RFC,24/32] qapi-options: Generate help string

Message ID 20171002152552.27999-25-armbru@redhat.com
State New
Headers show
Series Command line QAPIfication | expand

Commit Message

Markus Armbruster Oct. 2, 2017, 3:25 p.m. UTC
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi-options.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/scripts/qapi-options.py b/scripts/qapi-options.py
index 240c9021c7..820d70f71f 100644
--- a/scripts/qapi-options.py
+++ b/scripts/qapi-options.py
@@ -13,12 +13,15 @@  from qapi import *
 
 
 class QAPISchemaGenOptionVisitor(QAPISchemaVisitor):
+    # TODO keep help in source order
+    # TODO generate the part of help that shows syntax
     def __init__(self):
         self.decl = None
         self.defn = None
         self._shortopts = None
         self._longopts = None
         self._cases = None
+        self._help = None
 
     def visit_begin(self, schema):
         self.decl = ''
@@ -26,15 +29,22 @@  class QAPISchemaGenOptionVisitor(QAPISchemaVisitor):
         self._shortopts = ''
         self._longopts = ''
         self._cases = ''
+        self._help = []
 
     def visit_end(self):
         if self._cases:
             c_max = c_enum_const(args.prefix + 'QAPIOptionKind', '_MAX')
+            c_help = '\n    '.join([c_string(h) for h in self._help])
             self.decl += mcgen('''
+extern const char %(c_prefix)sqapi_options_help[];
+
 %(c_prefix)sQAPIOption *%(c_prefix)sqapi_options_parse(int argc, char *argv[]);
 ''',
                                c_prefix=c_name(args.prefix, protect=False))
             self.defn += mcgen('''
+const char %(c_prefix)sqapi_options_help[] =
+    %(c_help)s;
+
 %(c_prefix)sQAPIOption *%(c_prefix)sqapi_options_parse(int argc, char *argv[])
 {
     static const struct option longopts[] = {
@@ -72,6 +82,7 @@  class QAPISchemaGenOptionVisitor(QAPISchemaVisitor):
 }
 ''',
                                c_prefix=c_name(args.prefix, protect=False),
+                               c_help=c_help,
                                c_shortopts=c_string(self._shortopts),
                                longopts=self._longopts,
                                cases=self._cases,
@@ -79,6 +90,7 @@  class QAPISchemaGenOptionVisitor(QAPISchemaVisitor):
         self._shortopts = None
         self._longopts = None
         self._cases = None
+        self._help = None
 
     def visit_option(self, name, info, arg_type, short, implied_key,
                      boxed, help_):
@@ -140,6 +152,7 @@  case 256 + %(case)s:
 ''')
 
         pop_indent(8)
+        self._help += help_
 
 
 args = common_argument_parser().parse_args()