Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1564)

Unified Diff: shell/main.py

Issue 6720024: Plumb in subcommand options (Closed) Base URL: ssh://gitrw.chromium.org:9222/chromite.git@master
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | shell/subcmds/build_cmd.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
« no previous file with comments | « no previous file | shell/subcmds/build_cmd.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698