Mercurial > python-cmd2
comparison cmd2.py @ 37:a974e2f44cbe
made redirectors work with app-specific StatementEndPattern
author | catherine@localhost |
---|---|
date | Mon, 19 May 2008 15:23:42 -0400 |
parents | f472921d6189 |
children | 6d715d7a04fd |
comparison
equal
deleted
inserted
replaced
36:f472921d6189 | 37:a974e2f44cbe |
---|---|
44 optionParser.add_option(opt) | 44 optionParser.add_option(opt) |
45 optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_')) | 45 optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_')) |
46 def newFunc(instance, arg): | 46 def newFunc(instance, arg): |
47 try: | 47 try: |
48 opts, arg = optionParser.parse_args(arg.split()) | 48 opts, arg = optionParser.parse_args(arg.split()) |
49 arg = ' '.join(arg) | |
49 except (optparse.OptionValueError, optparse.BadOptionError, | 50 except (optparse.OptionValueError, optparse.BadOptionError, |
50 optparse.OptionError, optparse.AmbiguousOptionError, | 51 optparse.OptionError, optparse.AmbiguousOptionError, |
51 optparse.OptionConflictError), e: | 52 optparse.OptionConflictError), e: |
52 print e | 53 print e |
53 optionParser.print_help() | 54 optionParser.print_help() |
54 return | 55 return |
55 result = func(instance, ' '.join(arg), opts) | 56 result = func(instance, arg, opts) |
56 return result | 57 return result |
57 newFunc.__doc__ = '%s\n%s' % (func.__doc__, optionParser.format_help()) | 58 newFunc.__doc__ = '%s\n%s' % (func.__doc__, optionParser.format_help()) |
58 return newFunc | 59 return newFunc |
59 return option_setup | 60 return option_setup |
60 | 61 |
175 legalFileName = re.compile(r'''^[^"'\s]+$''') | 176 legalFileName = re.compile(r'''^[^"'\s]+$''') |
176 def parseRedirector(self, statement, symbol, mustBeTerminated=False): | 177 def parseRedirector(self, statement, symbol, mustBeTerminated=False): |
177 parts = statement.split(symbol) | 178 parts = statement.split(symbol) |
178 if (len(parts) < 2): | 179 if (len(parts) < 2): |
179 return statement, None | 180 return statement, None |
180 if mustBeTerminated and (parts[-2].strip()[-1] not in self.terminators): | 181 if mustBeTerminated and (not self.statementEndPattern.search(parts[-2])): |
181 return statement, None | 182 return statement, None |
182 (newStatement, redirect) = (symbol.join(parts[:-1]), parts[-1].strip()) | 183 (newStatement, redirect) = (symbol.join(parts[:-1]), parts[-1].strip()) |
183 if redirect: | 184 if redirect: |
184 if not self.legalFileName.search(redirect): | 185 if not self.legalFileName.search(redirect): |
185 return statement, None | 186 return statement, None |