// Check: arguments
$arguments_valid = true;
try {
    $cli->arguments->parse();
} catch (Exception $e) {
    $arguments_valid = false;
    if (!$cli->arguments->defined('help')) {
        $cli->red()->error($e->getMessage());
    }
}
if (!$arguments_valid || $cli->arguments->defined('help')) {
    $cli->usage();
    die;
}
// Check: output directory
$cli->inline(str_pad('Output directory exists and is writable', PADDING));
if (!is_dir($cli->arguments->get('output')) || !is_writeable($cli->arguments->get('output'))) {
    $cli->inline('[')->red()->inline('FAIL')->white()->out(']');
    $cli->red()->out('Please choose a writable directory!');
    die;
}
$cli->inline('[ ')->green()->inline('OK')->white()->out(' ]');
define('OUTPUT_DIR', realpath($cli->arguments->get('output')) . '/');
// Check: input
$input_ids = [];
if (!empty($cli->arguments->get('id'))) {
    $input_ids = explode(',', $cli->arguments->get('id'));
    array_walk($input_ids, 'trim');
    $input_ids = array_filter($input_ids, 'is_numeric');
    $cli->inline(str_pad('Input: ' . count($input_ids) . ' links', PADDING));
    if (0 === count($input_ids)) {
예제 #2
0
파일: publish.php 프로젝트: grynn/git
namespace Grynn;

require_once __DIR__ . "/vendor/autoload.php";
use CommandLine;
$st = microtime(true);
$climate = new \League\CLImate\CLImate();
$defaults = ['remote' => 'origin'];
//Parse command line
$opt = parseCommandLine($argv);
if (isset($opt['remote'])) {
    $remote = $opt['remote'];
} else {
    $remote = $defaults['remote'];
}
//Get project root (root of git && has composer.json)
$climate->inline("Detecting project root: ");
$git = new Git();
$root = $git->getRoot();
if (!file_exists($root . "/composer.json")) {
    errExit($climate, "Could not find composer.json! in {$root}");
    die;
}
$climate->green($root . " (" . round((microtime(true) - $st) * 1000) . " ms)");
//Validate composer.json
$st = microtime(true);
$climate->inline("Validating composer.json: ");
exec("composer validate", $output, $code);
if ($code != 0) {
    errExit($climate);
    echo join("\n", $output);
}