* handle opts in preparser, blah
* fixx0rz 533
This commit is contained in:
+7
-2
@@ -37,9 +37,10 @@ class PreParser(OptionParser):
|
|||||||
raise ParserError, msg
|
raise ParserError, msg
|
||||||
|
|
||||||
def parse_args(self, args=None):
|
def parse_args(self, args=None):
|
||||||
|
self.opts = []
|
||||||
self.rargs = self._get_args(args)
|
self.rargs = self._get_args(args)
|
||||||
self._process_args()
|
self._process_args()
|
||||||
return self.args
|
return (self.opts, self.args)
|
||||||
|
|
||||||
def _process_args(self):
|
def _process_args(self):
|
||||||
args = []
|
args = []
|
||||||
@@ -51,6 +52,7 @@ class PreParser(OptionParser):
|
|||||||
def option():
|
def option():
|
||||||
if not self.allow_interspersed_args and first_arg:
|
if not self.allow_interspersed_args and first_arg:
|
||||||
self.error_(('Options must precede non-option arguments'))
|
self.error_(('Options must precede non-option arguments'))
|
||||||
|
self.opts.append(rargs[0][2:])
|
||||||
del rargs[0]
|
del rargs[0]
|
||||||
return
|
return
|
||||||
# We handle bare "--" explicitly, and bare "-" is handled by the
|
# We handle bare "--" explicitly, and bare "-" is handled by the
|
||||||
@@ -80,8 +82,11 @@ class PisiCLI(object):
|
|||||||
self.parser = PreParser(version="%prog " + pisi.__version__)
|
self.parser = PreParser(version="%prog " + pisi.__version__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = self.parser.parse_args()
|
opts, args = self.parser.parse_args()
|
||||||
if len(args)==0: # more explicit than using IndexError
|
if len(args)==0: # more explicit than using IndexError
|
||||||
|
if 'version' in opts:
|
||||||
|
self.parser.print_version()
|
||||||
|
sys.exit(0)
|
||||||
printu(_('No command given'))
|
printu(_('No command given'))
|
||||||
self.die()
|
self.die()
|
||||||
cmd_name = args[0]
|
cmd_name = args[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user