First commit of cros tool.

This commits the basis of the cros tool with unittests. Ability to
find subcmds taken from previous chromite shell work.

cros is the base tool for cros-ui-v2. It finds cros_<tool_name> tools
from cros.commands. Currently, only the functionality for finding
and calling sub-tools has been implemented.

BUG=None
TEST=Unittests + ran tool with example tool + pylint

Change-Id: Ifeb1a8f7ea508cea8a2479f54f9bdd1bd52a3030
Reviewed-on: https://gerrit.chromium.org/gerrit/34837
Commit-Ready: Chris Sosa <sosa@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
diff --git a/scripts/cros.py b/scripts/cros.py
new file mode 100644
index 0000000..7d6f424
--- /dev/null
+++ b/scripts/cros.py
@@ -0,0 +1,42 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import sys
+
+# Older version of Python might be missing argparse.
+try:
+  import argparse
+except ImportError:
+  print >> sys.stderr, "argparse missing. sudo apt-get install python-argparse"
+  sys.exit(1)
+
+from chromite.cros import commands
+
+
+def GetOptions(commands):
+  """Returns the argparse to use for Cros."""
+  parser = argparse.ArgumentParser()
+  if not commands:
+    return parser
+
+  subparsers = parser.add_subparsers(title='cros commands')
+  for cmd_name, class_def in commands.iteritems():
+    sub_parser = subparsers.add_parser(cmd_name, help=class_def.__doc__)
+    class_def.AddParser(sub_parser)
+
+  return parser
+
+
+def main(args):
+  parser = GetOptions(commands.commands)
+  # Cros currently does nothing without a subcmd. Print help if no args are
+  # specified.
+  if not args:
+    parser.print_help()
+    return 1
+
+  namespace = parser.parse_args(args)
+  subcommand = namespace.cros_class(namespace)
+  subcommand.Run()
+  return 0