Пример #1
0
 protected function runCommandPrompt()
 {
     $command = new Command();
     $command->option('p')->aka('path')->file()->default($this->config->get('defaultFilePath'))->describedAs(sprintf('Result csv file path (%s is default)', $this->config->get('defaultFilePath')));
     $command->option('n')->aka('name')->default($this->config->get('defaultFileName'))->describedAs(sprintf('Result csv file name (%s is default)', $this->config->get('defaultFileName')));
     $command->option('y')->aka('year')->boolean()->default(false)->describedAs('Generate salary days for all current year (default for the reminder of current year)');
     $command->option('s')->aka('startDate')->default(null)->describedAs('start year and month in format (Y-m)');
     $command->option('e')->aka('endDate')->default(null)->describedAs('end year and month in format (Y-m)');
     return $command;
 }
 public function __construct(Slim $app, Command $command = null, CLImate $climate = null)
 {
     parent::__construct($app);
     $this->cliReader = $command ?: new Command();
     $this->cliWriter = $climate ?: new CLImate();
     // Define the first mandatory command
     $currentCommand = $this->app->router()->getCurrentRoute()->getPattern();
     $this->cliReader->option()->require()->describedAs('The command to execute')->must(function ($command) use($currentCommand) {
         return $currentCommand === $command;
     });
     $this->initCommand();
 }
Пример #3
0
 /**
  * Base constructor. Subclasses should call this first so the arguments 
  * required for tvheadend communication can be set
  * @param string $prefix prefix for the basic options, e.g. "source" 
  * changes the option "tvheadend-hostname" to "source-tvheadend-hostname"
  */
 public function __construct($prefix = '')
 {
     // Configure the logger
     $dateFormat = 'Y-m-d H:i:s';
     $output = "[%datetime%] %level_name%: %message%\n";
     $handler = new StreamHandler('php://stdout', Logger::DEBUG);
     $handler->setFormatter(new LineFormatter($output, $dateFormat));
     $this->logger = new Logger('logger');
     $this->logger->pushHandler($handler);
     $command = new Command();
     if (!empty($prefix)) {
         $prefix .= '-';
     }
     // Required arguments
     $command->option($prefix . 'tvheadend-hostname')->require()->describe('The hostname where tvheadend is running');
     // Optional arguments
     $command->option($prefix . 'tvheadend-http-port')->default(9981)->describe('The tvheadend HTTP port');
     $command->option($prefix . 'tvheadend-username')->describe('The tvheadend username');
     $command->option($prefix . 'tvheadend-password')->describe('The tvheadend password');
     $this->command = $command;
 }
Пример #4
0
 public static function fetchFromGoogle()
 {
     $trans_command = new Command();
     $trans_command->option('i')->aka('in')->describedAs("Input Language")->required()->default("en");
     $trans_command->option('o')->aka('out')->describedAs("Output Language");
     echo "Translate from {$trans_command['in']} to " . (isset($trans_command['out']) ? $trans_command['out'] : 'all') . "\n";
     $tr = new TranslateClient();
     $tr->setSource($trans_command['in']);
     $tr->setTarget($trans_command['out']);
     $langauges = Language::search()->exec();
     $untranslated_phrases = PhraseReplacement::search()->where('is_translated', 'No')->exec();
     foreach ($untranslated_phrases as $i => $phrase) {
         /* @var $phrase PhraseReplacement */
         /* @var $original PhraseOriginal */
         /* @var $langauge Language */
         $langauge = $langauges[$phrase->language_id];
         $translator = $tr->setTarget($langauge->code);
         $original = PhraseOriginal::search()->where('original_id', $phrase->original_id)->execOne();
         $output = $translator->translate($original->value);
         $phrase->value = $output;
         $phrase->is_translated = "Yes";
         $phrase->save();
     }
 }
Пример #5
0
 * > php greet.php -cs Mr 'nate good'
 * Hello Mr. Nate Good!
 *
 * > php greet.php -cs Mister 'nate good'
 * Hello Mr. Nate Good!
 * 
 * php greet.php -ceet Mr 'nate good'
 * Hello Mr. Nate Good esq!
 *
 * > php greet.php
 * # Throws an Exception because the command requires at least one
 * # anonymous option
 */
require dirname(__DIR__) . '/vendor/autoload.php';
use Commando\Command;
$hello_cmd = new Command();
$hello_cmd->option()->require()->title('name')->describedAs('A person\'s name')->option('t')->aka('title')->aka('long-title')->describedAs('When set, use this title to address the person')->must(function ($title) {
    $titles = array('Mister', 'Mr', 'Misses', 'Mrs', 'Miss', 'Ms');
    return in_array($title, $titles);
})->map(function ($title) {
    $titles = array('Mister' => 'Mr', 'Misses' => 'Mrs', 'Miss' => 'Ms');
    if (array_key_exists($title, $titles)) {
        $title = $titles[$title];
    }
    return "{$title}. ";
})->option('c')->aka('capitalize')->aka('cap')->describedAs('Always capitalize the words in a name')->boolean()->option('e')->aka('educate')->map(function ($value) {
    $postfix = array('', 'Jr', 'esq', 'PhD');
    return $postfix[$value] === '' ? '' : " {$postfix[$value]}";
})->count(4);
$name = $hello_cmd['capitalize'] ? ucwords($hello_cmd[0]) : $hello_cmd[0];
echo "Hello {$hello_cmd['title']}{$name}{$hello_cmd['educate']}!", PHP_EOL;
Пример #6
0
<?php

namespace Moccalotto\Reporter;

use Commando\Command;
require_once 'vendor/autoload.php';
$app = new App(['version' => '@git-version@', 'args' => function ($app) {
    $args = new Command();
    $args->argument()->aka('config')->describedAs('Use a given configuration file. Defaults to reporter.php if it exists.')->defaultsTo('reporter.php')->file()->must(function ($file) {
        Ensure::fileIsReadable($file);
        return true;
    });
    $args->option('d')->aka('dump-config')->map(function ($file) {
        if (null === $file) {
            return 'php://output';
        }
        return $file;
    })->must(function ($file) {
        Ensure::that(!is_dir($file), sprintf('Cannot dump config to %s. It is a directory', $file));
        if (is_file($file)) {
            Ensure::that(is_writable($file), sprintf('Cannot dump config to %s. It is not writable', $file));
        }
        return true;
    })->describedAs('Dump the config to the the specified file. Defaults to stdout.');
    $args->option('k')->aka('new-key')->map(function ($file) {
        if (null === $file) {
            return 'php://stdout';
        }
        return $file;
    })->must(function ($file) {
        Ensure::that(!is_dir($file), sprintf('Cannot dump config to %s. It is a directory', $file));
Пример #7
0
 /**
  * Test that an exception is thrown when an option isn't set
  * @expectedException \InvalidArgumentException
  */
 public function testRequirementsOnOptionsMissing()
 {
     $tokens = array('filename', '-a', 'v1');
     $cmd = new Command($tokens);
     $cmd->trapErrors(false)->beepOnError(false);
     $cmd->option('a')->needs('b');
 }
Пример #8
0
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
} else {
    require_once __DIR__ . '/../../../autoload.php';
}
use Commando\Command as CommandOptions;
use PhpTags\Database;
use PhpTags\ExtensionTags;
use PhpTags\Files;
use PhpTags\IndexCommand;
use PhpTags\Parser;
use PhpTags\QueryCommand;
// Setup generic options.
if (array_intersect(array('index', 'query'), $argv)) {
    $options = new CommandOptions();
    $options->option()->title('action')->describedAs('Possible actions: index, query');
    // The project root specifies the starting point of the recursive file
    // search. This allows running the command from outside of the project
    // directory.
    $options->option('root')->describedAs('Project root (defaults to current directory)')->must(function ($directory) {
        return is_dir($directory);
    });
    // It's possible to change the name of the SQLite database file. Absolute file
    // paths are allowed and the path does not have to be contained inside the
    // project root.
    $options->option('database')->describedAs('Location of SQLite database')->default('PHPTAGS.sqlite');
} else {
    print <<<USAGE
Usage:
        {$argv[0]} index [--help]
        {$argv[0]} query [PATTERN] [--help]
Пример #9
0
 /**
  * @param Command $cmdArgs
  */
 private function setCmdArgs($cmdArgs)
 {
     $cmdArgs->option('p')->require()->aka('path')->describedAs('Path to benchmark events.');
     $cmdArgs->flag('b')->aka('bootstrap')->describedAs('Path to bootstrap file for your project');
     $cmdArgs->flag('f')->aka('formatter')->describedAs('User-configured formatter to use instead of DefaultFormatter');
 }
<?php

require __DIR__ . "/../vendor/autoload.php";
use Commando\Command;
use Colors\Color;
use Common\Storage\Connection\Mysql;
$cmd = new Command();
$cmd->option('configPath')->describedAs('db config path to use for credentials')->require();
$cmd->option('group')->describedAs('group to use in db configs `default`');
$cmd->option('db')->describedAs('database name')->require();
$cmd->option('t')->aka('table')->describeAs("table to generate a model for")->require();
$cmd->option('e')->aka('environment')->describeAs("Environment to run mysql connection against")->require();
$cmd->option('d')->aka('directory')->describeAs("Directory to store the results")->require();
$cmd->option('n')->aka('namespace')->describeAs("Namespace for models")->require();
$mysql = new \Common\Storage\Connection\Mysql(array("environment" => $cmd['e'], "configPath" => $cmd['configPath'], "database" => $cmd['db'], "group" => $cmd['group']));
$columns = $mysql->getColumnList($cmd['db'], $cmd['t']);
$namespace = $cmd['n'];
$class = $cmd['table'];
$props = array();
foreach ($columns as $col => $details) {
    if (in_array($col, array('DateAdded', 'DateTimeAdded', 'LastUpdated'))) {
        continue;
    }
    $props[] = "\tpublic \$" . \Common\Tool\Introspection::modelizeName($col) . ";";
}
$props = implode(PHP_EOL . PHP_EOL, $props);
$output = <<<eot
<?php
namespace {$namespace};

use Common\\Model\\BaseModel;