Chromium Code Reviews| Index: shell/main.py |
| diff --git a/shell/main.py b/shell/main.py |
| index c847e9df2eb700192777befce68dc526347c6474..9fe19021061bbcb9529d5202d56a3795e15ecb84 100755 |
| --- a/shell/main.py |
| +++ b/shell/main.py |
| @@ -138,8 +138,29 @@ def main(): |
| help="Chroot spec to use. Can be an absolute path to a spec file " |
| "or a substring of a chroot spec name (without .spec suffix)") |
| parser.usage = help_str |
| + |
| + # We want to parse only the options that we understand at the top level of |
|
diandersAtChromium
2011/04/04 20:42:48
This code won't work, will it? Try:
chromite -v
|
| + # Chromite. Our heuristic here is that anything after the first positional |
| + # parameter (which we assume is the command) is ignored at this level, and |
| + # is passed down to the command level to handle. |
| + # FIXME(sjg): Revisit this to include tolerant option parser instead |
|
diandersAtChromium
2011/04/04 20:42:48
nit: please use TODO.
|
| + # http://codereview.chromium.org/6469035/ |
| + our_args = [] # Arguments that we will parse here |
| + cmd_args = [] # Arguments that we will pass down to the command level |
| + positional = 0 |
| + for arg in sys.argv: |
| + |
| + # Option arguments are collected as it, but we only allow two positional |
|
diandersAtChromium
2011/04/04 20:42:48
nit: "as is"
|
| + # arguments: argv[0] is the program name, the next is the command name. |
| + if positional == 2: |
| + cmd_args = sys.argv[len(our_args):] |
| + break |
| + if arg[0] != '-': |
| + positional += 1 |
| + our_args.append(arg) |
| + |
| try: |
| - (options, args) = parser.parse_args() |
| + (options, args) = parser.parse_args(our_args) |
| except: |
| sys.exit(1) |
| @@ -165,8 +186,7 @@ def main(): |
| # Get command and arguments |
| if args: |
| - cmd_str = args[0].lower() |
| - args = args[1:] |
| + cmd_str = args[1].lower() |
| else: |
| cmd_str = '' |
| @@ -179,7 +199,7 @@ def main(): |
| cmd_obj = cmd_cls() |
| cmd_obj.SetChromiteEnv(cros_env) |
| try: |
| - cmd_obj.Run([cmd_str] + args, chroot_config=chroot_config) |
| + cmd_obj.Run([cmd_str] + cmd_args, chroot_config=chroot_config) |
| # Handle an error in one of the scripts: print a message and exit. |
| except chromite_env.ChromiteError, msg: |