From c9b0f04b6968e1823ed38d9beea3f5b47b1f2ba9 Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Tue, 14 Jun 2011 19:18:09 +0200 Subject: [PATCH] handle -h, --help, --version --- sloth/core/labeltool.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index 68201ff..cd72105 100755 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -113,8 +113,8 @@ class LabelTool(QObject): except IndexError: subcommand = None - # handle commands - if subcommand == 'help' or subcommand == '-h' or subcommand == '--help': + # handle commands and command line arguments + if subcommand == 'help': if len(args) > 2: self.fetch_command(args[2]).print_help(self.prog_name, args[2]) sys.exit(0) @@ -123,6 +123,15 @@ class LabelTool(QObject): parser.print_lax_help() sys.exit(1) + elif self.argv[1:] == ['--version']: + # LaxOptionParser already takes care of printing the version. + sys.exit(0) + + elif self.argv[1:] in (['--help'], ['-h']): + sys.stdout.write(self.main_help_text() + '\n') + parser.print_lax_help() + sys.exit(0) + elif subcommand in get_commands(): self.fetch_command(subcommand).run_from_argv(self.argv) sys.exit(0)