From 72decfedaa9650d843c2c4e9c0c0e1fcbe226331 Mon Sep 17 00:00:00 2001 From: dsansome Date: Mon, 1 Aug 2016 20:55:46 -0700 Subject: [PATCH] If cit is run with an unknown tool, print usage rather than throwing an exception BUG= TBR=hinoka Review-Url: https://codereview.chromium.org/2181413004 --- cit.py | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/cit.py b/cit.py index b99411bc9..f08ddddc5 100755 --- a/cit.py +++ b/cit.py @@ -99,27 +99,7 @@ def get_available_tools(): return (sorted(infra_tools), sorted(cipd_tools)) -def run(args): - if args: - tool_name = args[0] - # Check to see if it is a infra tool first. - infra_dir = os.path.join( - TARGET_DIR, 'infra', 'infra', 'tools', *tool_name.split('.')) - cipd_file = os.path.join(TARGET_DIR, 'infra', 'cipd', tool_name) - if sys.platform.startswith('win'): - cipd_file += '.exe' - if (os.path.isdir(infra_dir) - and os.path.isfile(os.path.join(infra_dir, '__main__.py'))): - cmd = [ - sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'), - 'infra.tools.%s' % tool_name] - elif os.path.isfile(cipd_file) and is_exe(cipd_file): - cmd = [cipd_file] - - # Add the remaining arguments. - cmd.extend(args[1:]) - return subprocess.call(cmd) - +def usage(): infra_tools, cipd_tools = get_available_tools() print """usage: cit.py [args for tool] @@ -137,6 +117,32 @@ def run(args): print ' * %s' % tool +def run(args): + if not args: + return usage() + + tool_name = args[0] + # Check to see if it is a infra tool first. + infra_dir = os.path.join( + TARGET_DIR, 'infra', 'infra', 'tools', *tool_name.split('.')) + cipd_file = os.path.join(TARGET_DIR, 'infra', 'cipd', tool_name) + if sys.platform.startswith('win'): + cipd_file += '.exe' + if (os.path.isdir(infra_dir) + and os.path.isfile(os.path.join(infra_dir, '__main__.py'))): + cmd = [ + sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'), + 'infra.tools.%s' % tool_name] + elif os.path.isfile(cipd_file) and is_exe(cipd_file): + cmd = [cipd_file] + else: + print >>sys.stderr, 'Unknown tool "%s"' % tool_name + return usage() + + # Add the remaining arguments. + cmd.extend(args[1:]) + return subprocess.call(cmd) + def main(): parser = argparse.ArgumentParser("Chrome Infrastructure CLI.")