pygpt: Add new ExecuteCommandLine helper function for GPTCommand.SubCommand.

Some tool programs, for example image_tool, may want to run pygpt
command line sub commands (GPTCommand.SubCommand).

The new ExecuteCommandLine provides a simpler way to invoke quickly,
without worrying about how to deal with argparser.

BUG=chromium:834237
TEST=make test

Change-Id: I66fb9a8c38aef4973c5394a9d6ede38bf930a0fa
Reviewed-on: https://chromium-review.googlesource.com/1058047
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
diff --git a/py/utils/pygpt.py b/py/utils/pygpt.py
index 02ed9fa..ef04209 100755
--- a/py/utils/pygpt.py
+++ b/py/utils/pygpt.py
@@ -969,7 +969,9 @@
       raise NotImplementedError
 
     def Execute(self, args):
-      """Execute the command.
+      """Execute the command with parsed arguments.
+
+      To execute with raw arguments, use ExecuteCommandLine instead.
 
       Args:
         args: An argparse parsed namespace.
@@ -977,6 +979,19 @@
       del args  # Unused.
       raise NotImplementedError
 
+    def ExecuteCommandLine(self, *args):
+      """Execute as invoked from command line.
+
+      This provides an easy way to execute particular sub command without
+      creating argument parser explicitly.
+
+      Args:
+        args: a list of string type command line arguments.
+      """
+      parser = argparse.ArgumentParser()
+      self.DefineArgs(parser)
+      return self.Execute(parser.parse_args(args))
+
   class Create(SubCommand):
     """Create or reset GPT headers and tables.