-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
debug-schema
command to show the internal representation (#174)
Introduced a new `debug-schema` command in CSV Blueprint that shows the internal representation of the scheme with presets taken into account.
- Loading branch information
Showing
5 changed files
with
423 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Commands; | ||
|
||
use JBZoo\Cli\CliCommand; | ||
use JBZoo\CsvBlueprint\Schema; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class DebugSchema extends CliCommand | ||
{ | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setName('debug-schema') | ||
->setDescription('Show the internal representation of the schema taking into account presets.') | ||
->addOption( | ||
'schema', | ||
's', | ||
InputOption::VALUE_REQUIRED, | ||
\implode("\n", [ | ||
'Specify the path to a schema file, supporting YAML, JSON, or PHP formats. ', | ||
'Examples: <info>/full/path/name.yml</info>; <info>p/file.yml</info>', | ||
]), | ||
) | ||
->addOption( | ||
'hide-defaults', | ||
'd', | ||
InputOption::VALUE_NONE, | ||
'Hide default values in the output.', | ||
); | ||
|
||
parent::configure(); | ||
} | ||
|
||
protected function executeAction(): int | ||
{ | ||
$decorated = $this->outputMode->getOutput()->isDecorated(); | ||
|
||
$schemaFilename = $this->getOptString('schema'); | ||
if (!\file_exists($schemaFilename)) { | ||
throw new Exception("Schema file not found: {$schemaFilename}"); | ||
} | ||
|
||
$this->_((new Schema($schemaFilename))->dumpAsYamlString($this->getOptBool('hide-defaults'), $decorated)); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
Oops, something went wrong.