/** * Constructor. * * @param string $question The question you want to ask. * @param $default $default The default value. * @param IOInterface $io The input object. * * @since 2.0 */ function __construct($question = null, $default = null, IOInterface $io = null) { $this->io = $io ?: IOFactory::getIO(); $this->question = $question; $this->default = $default; $this->init(); }
/** * Initialise command. * * @return void * * @since 2.0 */ protected function init() { // Get application file name if (!$this->name) { $file = $_SERVER['argv'][0]; $file = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $file); $file = explode(DIRECTORY_SEPARATOR, $file); $file = array_pop($file); } else { $file = $this->name; } $this->setName($file)->description('The default application command')->help(<<<HELP Welcome to Windwalker Console. HELP ); $this->addGlobalOption(array('h', 'help'))->defaultValue(0)->description('Display this help message.'); $this->addGlobalOption(array('q', 'quiet'))->defaultValue(0)->description('Do not output any message.'); $this->addGlobalOption(array('v', 'verbose'))->defaultValue(0)->description('Increase the verbosity of messages.'); $this->addGlobalOption('ansi')->defaultValue(defined('PHP_WINDOWS_VERSION_MAJOR') ? false : true)->description("Set 'off' to suppress ANSI colors on unsupported terminals."); // Add a style <option> & <cmd> $this->io->addColor('option', 'cyan', '', array('bold'))->addColor('cmd', 'magenta', '', array('bold')); Console\IO\IOFactory::$io = $this->io; }