qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 24/32] qapi-options: Generate help string


From: Markus Armbruster
Subject: [Qemu-devel] [RFC PATCH 24/32] qapi-options: Generate help string
Date: Mon, 2 Oct 2017 17:25:44 +0200

Signed-off-by: Markus Armbruster <address@hidden>
---
 scripts/qapi-options.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

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()
-- 
2.13.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]