feat: Add GraphViz renderer (#53)
This will allow users to use the `dot` executable to produce any supported output. For example, as requested in #52, one can now output a SVG file. Here is an example: ```bash bin/dcv render -m graphviz -o output.svg --graphviz-output-format svg ``` Closes #52
This commit is contained in:
parent
60b3599c63
commit
3ff9b0ccff
1 changed files with 10 additions and 2 deletions
|
@ -12,7 +12,8 @@ $application->register('render')
|
|||
|
||||
->addOption('override', null, Console\Input\InputOption::VALUE_REQUIRED, 'Tag of the override file to use', 'override')
|
||||
->addOption('output-file', 'o', Console\Input\InputOption::VALUE_REQUIRED, 'Path to a output file (Only for "dot" and "image" output format)')
|
||||
->addOption('output-format', 'm', Console\Input\InputOption::VALUE_REQUIRED, 'Output format (one of: "dot", "image", "display")', 'display')
|
||||
->addOption('output-format', 'm', Console\Input\InputOption::VALUE_REQUIRED, 'Output format (one of: "dot", "image", "display", "graphviz")', 'display')
|
||||
->addOption('graphviz-output-format', null, Console\Input\InputOption::VALUE_REQUIRED, 'GraphViz Output format (see `man dot` for details)', 'svg')
|
||||
->addOption('only', null, Console\Input\InputOption::VALUE_IS_ARRAY | Console\Input\InputOption::VALUE_REQUIRED, 'Display a graph only for a given services')
|
||||
|
||||
->addOption('force', 'f', Console\Input\InputOption::VALUE_NONE, 'Overwrites output file if it already exists')
|
||||
|
@ -39,7 +40,7 @@ $application->register('render')
|
|||
$outputFile = $input->getOption('output-file') ?: getcwd().DIRECTORY_SEPARATOR.'docker-compose.'.('dot' === $outputFormat ? $outputFormat : 'png');
|
||||
$onlyServices = $input->getOption('only');
|
||||
|
||||
if (false === in_array($outputFormat, ['dot', 'image', 'display'])) {
|
||||
if (false === in_array($outputFormat, ['dot', 'image', 'display', 'graphviz'])) {
|
||||
throw new Console\Exception\InvalidArgumentException(sprintf('Invalid output format "%s". It must be one of "dot", "image" or "display".', $outputFormat));
|
||||
}
|
||||
|
||||
|
@ -141,6 +142,13 @@ $application->register('render')
|
|||
$renderer = new GraphViz();
|
||||
$renderer->display($graph);
|
||||
break;
|
||||
|
||||
case 'graphviz':
|
||||
$renderer = new GraphViz();
|
||||
$format = $input->getOption('graphviz-output-format');
|
||||
|
||||
file_put_contents($outputFile, $renderer->setFormat($format)->createImageData($graph));
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue