The goal is to be able to use '-help' alone, or with a sub-section, i.e. '-help network,usb'.
Signed-off-by: Laurent Vivier <lviv...@redhat.com> --- vl.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/vl.c b/vl.c index 584ca88..a4fa7e5 100644 --- a/vl.c +++ b/vl.c @@ -1932,6 +1932,7 @@ static void help(int exitcode) } #define HAS_ARG 0x0001 +#define IS_OPT 0x0002 typedef struct QEMUOption { const char *name; @@ -2703,12 +2704,21 @@ static const QEMUOption *lookup_opt(int argc, char **argv, popt++; } if (popt->flags & HAS_ARG) { - if (optind >= argc) { - error_report("requires an argument"); - exit(1); + if (popt->flags & IS_OPT) { + if (optind < argc && argv[optind][0] != '-') { + optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); + } else { + optarg = NULL; + } + } else { + if (optind >= argc) { + error_report("requires an argument"); + exit(1); + } + optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); } - optarg = argv[optind++]; - loc_set_cmdline(argv, optind - 2, 2); } else { optarg = NULL; } -- 2.1.0