1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-10-06 01:19:18 +02:00

- update cmdln.py to planned 1.0 version. The main changes are

related to points that were raised during employment in osc:

  # v0.8.3
  - Fix a bug where errors with passing an incorrect number of args to
    functions in do_foo() implementations would be masked.
  
  # v1.0.0
  - [backward incompat] `Cmdln.main()` no longer takes an `optparser`
    argument. Top-level option parsing has been changed so that top-level
    options for a `Cmdln` subclass can more naturally be defined and
    handled on the class definition. Changes:
    - `Cmdln.main()` calls `self.get_optparser` to get an option handler.
      Subclasses should overload this method for custom top-level options.
    - After option parsing, but before sub-command handling, the
      `self.postoptparse()` hook is called.
  - Add a `version` attribute on `Cmdln` subclasses. If set, the default
    top-level option parser will have a `--version` attribute.
  - [backward incompat] Simplify the StopProcessing/opts.stop handling for
    option handling in subcommands. The "opts" argument to "do_*"
    sub-command functions will no longer have a "stop" value.
    StopProcessing is now called StopOptionProcessing. This shouldn't
    affect simple usage of cmdln.py.
  
- adjust osc.commandline for these changes.
This commit is contained in:
Dr. Peter Poeml
2007-05-16 10:55:05 +00:00
parent 34a2310db3
commit fc6eaf68da
2 changed files with 81 additions and 118 deletions

View File

@@ -12,7 +12,6 @@ import conf
class Osc(cmdln.Cmdln):
"""usage:
osc [GLOBALOPTS] SUBCOMMAND [OPTS] [ARGS...]
osc help SUBCOMMAND
@@ -28,32 +27,34 @@ class Osc(cmdln.Cmdln):
"""
name = 'osc'
def __init__(self, *args, **kwargs):
cmdln.Cmdln.__init__(self, *args, **kwargs)
cmdln.Cmdln.do_help.aliases.append('h')
conf.get_config()
# set up and parse options before subcommand
self.optparser = cmdln.CmdlnOptionParser(self,
version=get_osc_version())
self.optparser.add_option('-H', '--http-debug', action='store_true',
def get_optparser(self):
"""this is the parser for "global" options (not specific to subcommand)"""
optparser = cmdln.CmdlnOptionParser(self, version=get_osc_version())
optparser.add_option('-H', '--http-debug', action='store_true',
default=conf.config['http_debug'],
help='debug HTTP traffic')
self.optparser.add_option('-A', '--apisrv', dest='apisrv',
optparser.add_option('-A', '--apisrv', dest='apisrv',
metavar='URL',
help='specify URL to access API server at')
return optparser
(self.global_opts, self.myargs) = self.optparser.parse_args()
# XXX version is printed twice otherwise...
self.optparser.version = ''
def postoptparse(self):
"""merge commandline options into the config"""
# merge commandline options into the config
conf.config['http_debug'] = self.global_opts.http_debug
if self.global_opts.apisrv:
conf.config['http_debug'] = self.options.http_debug
if self.options.apisrv:
conf.config['scheme'], conf.config['apisrv'] = \
conf.parse_apisrv_url(conf.config['scheme'], self.global_opts.apisrv)
conf.parse_apisrv_url(conf.config['scheme'], self.options.apisrv)
conf.config['apiurl'] = conf.config['scheme'] + '://' + conf.config['apisrv']
# XXX unless config['user'] goes away (and is replaced with a handy function, or