Fix command output
authorGuido Günther <agx@sigxcpu.org>
Thu, 27 Mar 2014 20:22:25 +0000 (21:22 +0100)
committerGuido Günther <agx@sigxcpu.org>
Thu, 27 Mar 2014 20:22:25 +0000 (21:22 +0100)
The first line lacked the subcommand like:

$ gbp pull --help
Usage: gbp [options] - safely update a repository from remote

instead of

$ gbp pull --help
Usage: gbp pull [options] - safely update a repository from remote
           ^^^^

gbp/config.py
gbp/scripts/buildpackage.py
gbp/scripts/clone.py
gbp/scripts/create_remote_repo.py
gbp/scripts/dch.py
gbp/scripts/import_dsc.py
gbp/scripts/import_orig.py
gbp/scripts/pq.py
gbp/scripts/pull.py

index fa6e679..9ac1ee8 100644 (file)
@@ -20,6 +20,7 @@ from optparse import OptionParser, OptionGroup, Option, OptionValueError
 from ConfigParser import SafeConfigParser, NoSectionError
 from copy import copy
 import os.path
+import sys
 try:
     from gbp.version import gbp_version
 except ImportError:
@@ -356,7 +357,7 @@ class GbpOptionParser(OptionParser):
         else:
             self.config['filter'] = []
 
-    def __init__(self, command, prefix='', usage=None, sections=[]):
+    def __init__(self, command=None, prefix='', usage=None, sections=[]):
         """
         @param command: the command to build the config parser for
         @type command: C{str}
@@ -368,6 +369,10 @@ class GbpOptionParser(OptionParser):
             to parse
         @type sections: C{list} of C{str}
         """
+        if not command:
+            command = os.path.basename(sys.argv[0])
+            if command == 'gbp':
+                command += " " + os.path.basename(sys.argv[1])
         self.command = command
         self.sections = sections
         self.prefix = prefix
@@ -375,6 +380,7 @@ class GbpOptionParser(OptionParser):
         self.config_files = self.get_config_files()
         self._parse_config_files()
         OptionParser.__init__(self, option_class=GbpOption,
+                              prog=command,
                               usage=usage, version='%s %s' % (self.command,
                                                               gbp_version))
 
index 753ad64..0b14b3f 100755 (executable)
@@ -375,7 +375,7 @@ def parse_args(argv, prefix):
             args.append(arg)
 
     try:
-        parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix=prefix)
+        parser = GbpOptionParserDebian(prefix=prefix)
     except ConfigParser.ParsingError as err:
         gbp.log.err(err)
         return None, None, None
index 251cef2..1ddee3f 100755 (executable)
@@ -31,8 +31,7 @@ import gbp.log
 
 def parse_args (argv):
     try:
-        parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='',
-                                 usage='%prog [options] repository - clone a remote repository')
+        parser = GbpOptionParser(usage='%prog [options] repository - clone a remote repository')
     except ConfigParser.ParsingError as err:
         gbp.log.err(err)
         return None, None
index c8c4a36..95a10b0 100644 (file)
@@ -245,8 +245,7 @@ def parse_args(argv, sections=[]):
     else:
         sections = []
 
-    parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
-                                   usage='%prog [options] - '
+    parser = GbpOptionParserDebian(usage='%prog [options] - '
                                    'create a remote repository',
                                    sections=sections)
     branch_group = GbpOptionGroup(parser,
index a848d6d..30c90d1 100644 (file)
@@ -292,8 +292,7 @@ def main(argv):
     branch = None
 
     try:
-        parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
-                                       usage='%prog [options] paths')
+        parser = GbpOptionParserDebian(usage='%prog [options] paths')
     except ConfigParser.ParsingError as err:
         gbp.log.err(err)
         return 1
index 630422b..cbc67f0 100644 (file)
@@ -207,8 +207,7 @@ def set_bare_repo_options(options):
 
 def parse_args(argv):
     try:
-        parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
-                                       usage='%prog [options] /path/to/package.dsc')
+        parser = GbpOptionParserDebian(usage='%prog [options] /path/to/package.dsc')
     except ConfigParser.ParsingError as err:
         gbp.log.err(err)
         return None, None
index aae93fa..968aadb 100644 (file)
@@ -183,8 +183,7 @@ def set_bare_repo_options(options):
 
 def parse_args(argv):
     try:
-        parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
-                                       usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan')
+        parser = GbpOptionParserDebian(usage='%prog [options] /path/to/upstream-version.tar.gz | --uscan')
     except ConfigParser.ParsingError as err:
         gbp.log.err(err)
         return None, None
index 41d3ddf..5e94126 100755 (executable)
@@ -212,8 +212,7 @@ def switch_pq(repo, current):
 
 def parse_args(argv):
     try:
-        parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='',
-                                   usage="%prog [options] action - maintain patches on a patch queue branch\n"
+        parser = GbpOptionParserDebian(usage="%prog [options] action - maintain patches on a patch queue branch\n"
         "Actions:\n"
         "  export         export the patch queue associated to the current branch\n"
         "                 into a quilt patch series in debian/patches/ and update the\n"
index 03be9fc..6cc47d4 100755 (executable)
@@ -70,8 +70,7 @@ def fast_forward_branch(branch, repo, options):
 
 def parse_args(argv):
     try:
-        parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='',
-                             usage='%prog [options] - safely update a repository from remote')
+        parser = GbpOptionParser(usage='%prog [options] - safely update a repository from remote')
     except ConfigParser.ParsingError as err:
         gbp.log.err(err)
         return None, None