Skip to content

Commit

Permalink
[Console] made the defaults in Application more easily customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 25, 2011
1 parent cc01c2c commit de9f123
Showing 1 changed file with 48 additions and 18 deletions.
66 changes: 48 additions & 18 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,12 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
$this->catchExceptions = true;
$this->autoExit = true;
$this->commands = array();
$this->helperSet = new HelperSet(array(
new FormatterHelper(),
new DialogHelper(),
));

$this->add(new HelpCommand());
$this->add(new ListCommand());

$this->definition = new InputDefinition(array(
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
$this->helperSet = $this->getDefaultHelperSet();
$this->definition = $this->getDefaultInputDefinition();

new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
));
foreach ($this->getDefaultCommands() as $command) {
$this->add($command);
}
}

/**
Expand Down Expand Up @@ -809,6 +796,49 @@ protected function getCommandName(InputInterface $input)
return $input->getFirstArgument('command');
}

/**
* Gets the default input definition.
*
* @return InputDefinition An InputDefinition instance
*/
protected function getDefaultInputDefinition()
{
return new InputDefinition(array(
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),

new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
));
}

/**
* Gets the default commands that should always be available.
*
* @return array An array of default Command instances
*/
protected function getDefaultCommands()
{
return array(new HelpCommand(), new ListCommand());
}

/**
* Gets the default helper set with the helpers that should always be available.
*
* @return HelperSet A HelperSet instance
*/
protected function getDefaultHelperSet()
{
return new HelperSet(array(
new FormatterHelper(),
new DialogHelper(),
));
}

/**
* Sorts commands in alphabetical order.
*
Expand Down

0 comments on commit de9f123

Please sign in to comment.