Ejemplo n.º 1
0
ini_set('track_errors', 1);
date_default_timezone_set('America/Montreal');
$paths = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
foreach ($paths as $path) {
    if (file_exists($path)) {
        require_once $path;
        break;
    }
}
$cli = new Cli();
$cli->opt('token', 'The github access token. Uses the GITHUB_API_TOKEN if not specified.')->opt('quiet:q', "Don't output verbose information.", false, 'boolean')->command('labels')->description('Copy the labels from one github repo to another.')->opt('from:f', 'The github repo to copy the labels from.', true)->opt('to:t', 'The github repo to copy the labels to.', true)->opt('delete:d', 'Pass one of force or prune to force delete or prune unused labels.', false)->command('milestones')->description('Copy milestones from one github repo to another.')->opt('from:f', 'The github repo to copy the labels from.', true)->opt('to:t', 'The github repo to copy the labels to.', true)->opt('status:s', 'The milestone status. One of open, closed, all. Defaults to open.')->opt('autoclose', 'Whether or not to close milestones that are overdue and don\'t have any items.', false, 'boolean')->command('overdue')->description('Label issues from an past due milestones as overdue.')->opt('repo:r', 'The github repo to inspect.', true);
$args = $cli->parse($argv);
try {
    $sync = new \Vanilla\Github\GithubSync($args->getOpt('token', getenv('GITHUB_API_TOKEN')));
    $sync->setFromRepo($args->getOpt('from'))->setToRepo($args->getOpt('to'))->setMessageLevel($args->getOpt('quiet') ? 1 : 3);
    switch ($args->getCommand()) {
        case 'labels':
            $sync->syncLabels($args->getOpt('delete'));
            break;
        case 'milestones':
            $sync->syncMilestones($args->getOpt('status', 'open'), $args->getOpt('autoclose', false));
            break;
        case 'overdue':
            $sync->setFromRepo($args->getOpt('repo'));
            $sync->labelOverdue();
            break;
    }
} catch (Exception $ex) {
    echo $cli->red($ex->getMessage());
    return $ex->getCode();
}
Ejemplo n.º 2
0
    if (file_exists($path)) {
        require_once $path;
        break;
    }
}
use Garden\Cli\Cli;
use Garden\Cli\Schema;
use Mustacher\Mustacher;
$cli = new Cli();
$cli->description('Run mustache templates against a JSON file.')->opt('template:t', 'The path to the template file.', true)->opt('input:i', 'The path to the input JSON data file.')->opt('output:o', 'The path where the output will be written.')->opt('format:f', 'The format of the template file. Either mustache or message.')->opt('data:d', 'A JSON formatted data object. This will be merged on top of the input file if both are specified.');
$args = $cli->parse($argv);
try {
    $data = Mustacher::mergeData($args->getOpt('input'), $args->getOpt('data'));
    $str = Mustacher::generateFile($args->getOpt('template'), $data, $args->getOpt('format', Mustacher::FORMAT_MUSTACHE));
} catch (Exception $ex) {
    echo $cli->red($ex->getMessage() . "\n");
    die;
}
if ($args->getOpt('output')) {
    $path = $args->getOpt('output');
    if (!file_exists(dirname($path))) {
        mkdir($path, 0777, true);
    }
    echo "Writing output file: {$path}\n";
    $r = file_put_contents($path, $str);
    if ($r === false) {
        echo $cli->red("Error writing output file.\n");
    }
} else {
    echo $str;
}