From ecbd3cbe70f1621d4579793693efc8b709720ec1 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 12 Oct 2012 15:11:47 +0800 Subject: [PATCH] MDL-37046 behat: CLI tool --- admin/tool/behat/cli/util.php | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 admin/tool/behat/cli/util.php diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php new file mode 100644 index 00000000000..e76bdedf341 --- /dev/null +++ b/admin/tool/behat/cli/util.php @@ -0,0 +1,85 @@ +. + +/** + * 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')); -- 2.43.0