scripts: add west build, flash, and debug commands

West now supports a mechanism for extension commands. Use it to move
the command implementations that are tightly coupled with boards and
the zephyr build system back into the Zephyr repository.

This patch doesn't include test cases. Those will be moved over in a
subsequent patch.

Signed-off-by: Marti Bolivar <marti@foundries.io>
diff --git a/scripts/west_commands/flash.py b/scripts/west_commands/flash.py
new file mode 100644
index 0000000..dd03675
--- /dev/null
+++ b/scripts/west_commands/flash.py
@@ -0,0 +1,31 @@
+# Copyright (c) 2018 Open Source Foundries Limited.
+# Copyright 2019 Foundries.io
+#
+# SPDX-License-Identifier: Apache-2.0
+
+'''west "flash" command'''
+
+from textwrap import dedent
+
+from west.commands import WestCommand
+
+from run_common import desc_common, add_parser_common, do_run_common
+
+
+class Flash(WestCommand):
+
+    def __init__(self):
+        super(Flash, self).__init__(
+            'flash',
+            'flash and run a binary on a board',
+            dedent('''
+            Connects to the board and reprograms it with a new binary\n\n''') +
+            desc_common('flash'),
+            accepts_unknown_args=True)
+
+    def do_add_parser(self, parser_adder):
+        return add_parser_common(parser_adder, self)
+
+    def do_run(self, my_args, runner_args):
+        do_run_common(self, my_args, runner_args,
+                      'ZEPHYR_BOARD_FLASH_RUNNER')