MDL-37046 behat: CLI tool
authorDavid Monllao <davidm@moodle.com>
Fri, 12 Oct 2012 07:11:47 +0000 (15:11 +0800)
committerDavid Monllao <davidm@moodle.com>
Tue, 29 Jan 2013 00:40:35 +0000 (08:40 +0800)
admin/tool/behat/cli/util.php [new file with mode: 0644]

diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php
new file mode 100644 (file)
index 0000000..e76bded
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * CLI script
+ *
+ * @package    tool_behat
+ * @copyright  2012 David Monllaó
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('CLI_SCRIPT', true);
+
+require(__DIR__ . '/../../../../config.php');
+require_once($CFG->libdir . '/clilib.php');
+require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/behat/locallib.php');
+
+// now get cli options
+list($options, $unrecognized) = cli_get_params(
+    array(
+        'help            '   => false,
+        'stepsdefinitions'   => false,
+        'buildconfigfile'    => false,
+        'runtests'           => false
+    ),
+    array(
+        'h' => 'help'
+    )
+);
+
+$help = "
+Behat tool
+
+Ensure the user who executes the action has permissions over behat installation
+
+Options:
+--stepsdefinitions   Displays the available steps definitions
+--buildconfigfile    Updates the Moodle components config file
+--runtests           Runs the tests
+
+-h, --help     Print out this help
+
+Example from Moodle root directory:
+\$ php admin/tool/behat/cli/util --stepsdefinitions
+";
+
+if (!empty($options['help'])) {
+    echo $help;
+    exit(0);
+}
+
+if ($unrecognized) {
+    $unrecognized = implode("\n  ", $unrecognized);
+    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
+}
+
+$commands = array('stepsdefinitions', 'buildconfigfile', 'runtests');
+foreach ($commands as $command) {
+    if (isset($options[$command])) {
+        $action = $command;
+    }
+}
+
+if (!$action) {
+    mtrace('No command selected');
+    echo $help;
+    exit(0);
+}
+
+call_user_func('tool_behat::' . $action);
+
+mtrace(get_string('finished', 'tool_behat'));