Beispiel #1
0
 public function trigger()
 {
     $target_option = $this->getTarget();
     $target_plugin = $this->plugins->getPluginByNamespace($target_option);
     $child_arguments = new Arguments(array('input' => array_slice($_SERVER['argv'], 2)));
     $child_arguments->addFlag(array('version', 'v'), '查看版本信息')->addFlag(array('help', 'h'), '查看帮助信息')->addFlags($target_plugin->getFlags())->addOptions($target_plugin->getOptions());
     $child_arguments->parse();
     if ($child_arguments['help']) {
         die($child_arguments->getHelpScreen() . PHP_EOL . PHP_EOL);
     } elseif ($child_arguments['version']) {
         die($target_plugin->getNamespace() . ':' . $target_plugin->getVersion() . PHP_EOL . PHP_EOL);
     } else {
         $children_option = array_keys(array_merge($target_plugin->getOptions(), $target_plugin->getFlags()));
         $child_option = null;
         $child_argument_arr = array();
         foreach ($children_option as $option) {
             if (isset($child_arguments[$option])) {
                 $child_argument_arr[$option] = $child_arguments[$option];
             }
         }
         if (empty($child_argument_arr)) {
             die($child_arguments->getHelpScreen() . PHP_EOL . PHP_EOL);
         } else {
             $target_plugin->exec($child_argument_arr);
         }
     }
 }
Beispiel #2
0
 /**
  * Returns the available commands the Console provides
  * @see \cli\Arguments
  * @param string $strict
  * @param string $force
  * @return \cli\Arguments
  */
 public function getArgs($strict = false, $force = false)
 {
     if (is_null($this->args) || $force) {
         $this->args = new \cli\Arguments($strict);
         $this->args->addFlag(array('verbose', 'v'), 'Turn on verbose output');
         $this->args->addFlag('version', 'Display the version');
         $this->args->addFlag(array('help', 'h'), 'Show this help screen');
     }
     return $this->args;
 }
Beispiel #3
0
 /**
  * @see \qtism\cli\Cli::setupArguments()
  */
 protected function setupArguments()
 {
     $arguments = new Arguments(array('strict' => false));
     // -- Options
     // Flavour option.
     $arguments->addOption(array('flavour'), array('default' => 'xhtml', 'description' => 'Rendering flavour.'));
     // Source option.
     $arguments->addOption(array('source'), array('description' => 'QTI XML source to be rendered.'));
     // XMLBase option.
     $arguments->addOption(array('xmlbase'), array('default' => 'process', 'description' => 'xml:base behaviour.'));
     // -- Flags
     // Document flag.
     $arguments->addFlag(array('document', 'd'), 'Embed the rendering into a document.');
     // Format flag.
     $arguments->addFlag(array('format', 'f'), 'Format the rendering output with indentation.');
     // Novalidate flag.
     $arguments->addFlag(array('novalidate', 'n'), 'Do not validate QTI XML source.');
     // CSS Class Hierarchy flag.
     $arguments->addFlag(array('csshierarchy', 'c'), 'Full qti- CSS class hierarchy.');
     return $arguments;
 }
 /**
  * Parse input arguments
  */
 public function parse()
 {
     try {
         parent::parse();
         if ($this['help']) {
             echo PHP_EOL;
             die($this->getHelpScreen() . PHP_EOL . PHP_EOL);
         }
         // Check if there's YML argument file
         $ymlconfig = $this->processYMLfile();
         if ($ymlconfig !== false) {
             foreach ($ymlconfig as $key => $value) {
                 if (!isset($this[$key])) {
                     $this->offsetSet($key, $value);
                 }
             }
         }
         // Check undefined required arguments
         $undefined = [];
         foreach (self::$required as $required_field) {
             if (!isset($this[$required_field])) {
                 $undefined[] = $required_field;
             }
         }
         // If there are undefined required arguments
         if (sizeof($undefined) > 0) {
             throw new RequiredArgumentException($undefined);
         }
     } catch (\cli\arguments\InvalidArguments $ex) {
         $arguments = $ex->getArguments();
         array_walk($arguments, function (&$value) {
             $value = "    " . $value . PHP_EOL;
         });
         echo "Invalid arguments supplied: " . PHP_EOL . PHP_EOL;
         foreach ($arguments as $arg) {
             echo $arg;
         }
         echo PHP_EOL;
         die($this->getHelpScreen() . PHP_EOL . PHP_EOL);
     } catch (RequiredArgumentException $ex) {
         echo $ex->getMessage() . ': ' . implode(', ', $ex->getArguments()) . PHP_EOL;
         die($this->getHelpScreen() . PHP_EOL . PHP_EOL);
     } catch (\Exception $ex) {
         die($arguments = $ex->getMessage() . PHP_EOL . PHP_EOL);
     }
 }
Beispiel #5
0
<?php

use Cli\Arguments;
require '../vendor/autoload.php';
$arguments = new Arguments();
$arguments->addArgument('name', array('help' => 'Name to greet', 'default' => 'World'));
$arguments->addFlag(array('c', 'capitals'));
try {
    $options = $arguments->parse();
} catch (\Cli\ParsingException $e) {
    echo $e->getMessage();
}
$name = $options['name'];
if ($options['capitals']) {
    $name = strtoupper($name);
}
echo 'Hello, ' . $name . '!';
 /**
  * Generic private testParse method.
  *
  * @param  array $args           arguments as they appear in the cli
  * @param  array $expectedValues expected values after parsing
  */
 private function _testParse($cliParams, $expectedValues)
 {
     self::pushToArgv($cliParams);
     $args = new cli\Arguments($this->settings);
     $args->parse();
     foreach ($expectedValues as $name => $value) {
         if ($args->isFlag($name)) {
             $this->assertTrue($args[$name]);
         }
         if ($args->isOption($name)) {
             $this->assertEquals($value, $args[$name]);
         }
     }
 }
Beispiel #7
0
<?php

namespace potrans;

/**
 * @author Roman Ozana <*****@*****.**>
 */
use cli\Arguments;
use cli\Colors;
use cli\progress\Bar;
use Sepia\PoParser;
require_once __DIR__ . '/../vendor/autoload.php';
Colors::enable();
$arguments = new Arguments(compact('strict'));
$arguments->addOption(['apikey', 'k'], ['description' => 'Google Translate API Key']);
$arguments->addOption(['input', 'i'], ['description' => 'Path to input PO file']);
$arguments->addOption(['output', 'o'], ['description' => 'Path to output PO file (default: ./tmp/*.po)']);
$arguments->addOption(['from', 'f'], ['default' => 'en', 'description' => 'Source language (default: en)']);
$arguments->addOption(['to', 't'], ['default' => 'cs', 'description' => 'Target language (default: cs)']);
$arguments->addFlag(['verbose', 'v'], 'Turn on verbose output');
$arguments->addFlag(['help', 'h'], 'Show help');
$arguments->parse();
$apikey = $arguments['apikey'];
$input = $arguments['input'];
$output = $arguments['output'] ? $arguments['output'] : __DIR__ . '/../tmp/' . basename($input);
$from = $arguments['from'] ? $arguments['from'] : 'en';
$to = $arguments['to'] ? $arguments['to'] : 'cs';
$verbose = (bool) $arguments['verbose'];
if ($arguments['help'] || !$apikey || !$input) {
    echo str_repeat('-', 80) . PHP_EOL;
    echo 'PO translator parametters ' . PHP_EOL;
Beispiel #8
0
 /**
  * Register arguments available via the CLI.
  *
  * @return cli\Arguments An arguments object.
  */
 protected function registerArgs()
 {
     $args = new cli\Arguments();
     if (!empty($this->flags)) {
         $args->addFlags($this->flags);
     }
     if (!empty($this->options)) {
         $args->addOptions($this->options);
     }
     $args->parse();
     return $args;
 }
Beispiel #9
0
 public function consumeArgumentOptions(Arguments $arguments)
 {
     $data = $this->_consume($arguments->getOptions());
     $this->_options = $data[0];
     $this->_optionMax = $data[1];
 }