protected function describeApplication(Application $application, array $options = array())
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
- $description = new ApplicationDescription($application, $describedNamespace);
+ $description = new ApplicationDescription($application, $describedNamespace, true);
$commands = array();
foreach ($description->getCommands() as $command) {
$commands[] = $this->getCommandData($command);
}
- $data = $describedNamespace
- ? array('commands' => $commands, 'namespace' => $describedNamespace)
- : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));
+ $data = array();
+ if ('UNKNOWN' !== $application->getName()) {
+ $data['application']['name'] = $application->getName();
+ if ('UNKNOWN' !== $application->getVersion()) {
+ $data['application']['version'] = $application->getVersion();
+ }
+ }
+
+ $data['commands'] = $commands;
+
+ if ($describedNamespace) {
+ $data['namespace'] = $describedNamespace;
+ } else {
+ $data['namespaces'] = array_values($description->getNamespaces());
+ }
$this->writeData($data, $options);
}
/**
* Writes data as json.
*
- * @param array $data
- * @param array $options
- *
* @return array|string
*/
private function writeData(array $data, array $options)
}
/**
- * @param InputArgument $argument
- *
* @return array
*/
private function getInputArgumentData(InputArgument $argument)
'is_required' => $argument->isRequired(),
'is_array' => $argument->isArray(),
'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()),
- 'default' => $argument->getDefault(),
+ 'default' => INF === $argument->getDefault() ? 'INF' : $argument->getDefault(),
);
}
/**
- * @param InputOption $option
- *
* @return array
*/
private function getInputOptionData(InputOption $option)
{
return array(
'name' => '--'.$option->getName(),
- 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
+ 'shortcut' => $option->getShortcut() ? '-'.str_replace('|', '|-', $option->getShortcut()) : '',
'accept_value' => $option->acceptValue(),
'is_value_required' => $option->isValueRequired(),
'is_multiple' => $option->isArray(),
'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()),
- 'default' => $option->getDefault(),
+ 'default' => INF === $option->getDefault() ? 'INF' : $option->getDefault(),
);
}
/**
- * @param InputDefinition $definition
- *
* @return array
*/
private function getInputDefinitionData(InputDefinition $definition)
}
/**
- * @param Command $command
- *
* @return array
*/
private function getCommandData(Command $command)
'description' => $command->getDescription(),
'help' => $command->getProcessedHelp(),
'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
+ 'hidden' => $command->isHidden(),
);
}
}