diff options
author | Michael Tokarev <mjt@tls.msk.ru> | 2025-05-31 20:15:45 +0300 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2025-07-15 20:49:01 +0200 |
commit | fef5f1d4aa60360226bc15288611998b3699618f (patch) | |
tree | 8860ca34133abd947e3d35d307bb5306fae490c7 /scripts/tracetool/backend/log.py | |
parent | 443761ab3874d0ffc2df0a0cd73dd1ca833b277e (diff) | |
download | qemu-fef5f1d4aa60360226bc15288611998b3699618f.zip qemu-fef5f1d4aa60360226bc15288611998b3699618f.tar.gz qemu-fef5f1d4aa60360226bc15288611998b3699618f.tar.bz2 |
qemu-img: global option processing and error printing
In order to correctly print executable name in various
error messages, pass argv[0] to error_exit() function.
This way, error messages will refer to actual executable
name, which may be different from 'qemu-img'.
For subcommands, pass original command name from the
qemu-img argv[0], plus the subcommand name, as its own
argv[0] element, so error messages can be more useful.
Also don't require at least 3 options on the command
line: it makes no sense with options before subcommand.
Introduce tryhelp() function which just prints
try 'command-name --help' for more info
and exits. When tryhelp() is called from within a subcommand
handler, the message will look like:
try 'command-name subcommand --help' for more information
qemu-img uses getopt_long() with ':' as the first char in
optstring parameter, which means it doesn't print error
messages but return ':' or '?' instead, and qemu-img uses
unrecognized_option() or missing_argument() function to
print error messages. But it doesn't quite work:
$ ./qemu-img -xx
qemu-img: unrecognized option './qemu-img'
so the aim is to let getopt_long() to print regular error
messages instead (removing ':' prefix from optstring) and
remove handling of '?' and ':' "options" entirely. With
concatenated argv[0] and the subcommand, it all finally
does the right thing in all cases. This will be done in
subsequent changes command by command, with main() done
last.
unrecognized_option() and missing_argument() functions
prototypes aren't changed by this patch, since they're
called from many places and will be removed a few patches
later. Only artifical "qemu-img" argv0 is provided in
there for now.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250531171609.197078-4-mjt@tls.msk.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'scripts/tracetool/backend/log.py')
0 files changed, 0 insertions, 0 deletions