-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathteam51-cli.php
executable file
·46 lines (39 loc) · 1.79 KB
/
team51-cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\EventDispatcher\EventDispatcher;
const TEAM51_CLI_ROOT_DIR = __DIR__;
const TEAM51_CLI_FILE = __FILE__;
require_once TEAM51_CLI_ROOT_DIR . '/self-update.php';
require_once TEAM51_CLI_ROOT_DIR . '/vendor/autoload.php';
$team51_cli_app = new Application();
$team51_cli_input = new ArgvInput();
$team51_cli_output = new ConsoleOutput();
$team51_cli_dispatcher = new EventDispatcher();
// Handle errors gracefully.
$team51_cli_app->setDispatcher( $team51_cli_dispatcher );
$team51_cli_dispatcher->addListener(
ConsoleEvents::ERROR,
function ( ConsoleErrorEvent $event ) {
$message = implode( ' ', array( $event->getError()->getMessage(), 'Aborting!' ) );
$event->getOutput()->writeln( "<error>$message</error>" );
}
);
// Must be loaded after the application is instantiated, so we can use all the helper functions.
if ( ! $GLOBALS['team51_is_autocomplete'] ) {
require_once TEAM51_CLI_ROOT_DIR . '/load-identity.php';
}
foreach ( glob( __DIR__ . '/commands/*.php' ) as $command ) {
$command = '\\WPCOMSpecialProjects\\CLI\\Command\\' . basename( $command, '.php' );
$team51_cli_app->add( new $command() );
}
foreach ( $team51_cli_app->all() as $command ) {
$command->addOption( '--dev', null, InputOption::VALUE_NONE, 'Run the CLI tool in developer mode.' );
$command->addOption( '--no-autocomplete', null, InputOption::VALUE_NONE, 'Do not provide options to initialization questions.' );
}
$team51_cli_app->run( $team51_cli_input, $team51_cli_output );