Skip to content

Commit

Permalink
Hotfix: pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-deluna committed Feb 19, 2024
1 parent 15a32ee commit 8bca5ce
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/Command/SiliconGenDocSymbolsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,33 @@ class SiliconGenDocSymbolsCommand extends Command
'prefix' => 'o',
'description' => "The path to the output file. If not set it will be written to the default output path.",
'castTo' => 'string'
],
'print' => [
'prefix' => 'p',
'description' => "Prints the symbols as json to the console.",
'castTo' => 'bool',
'noValue' => true
]
];

/**
* @return array<string, string>
*/
private function getPathVars() : array
{
return [
'{silicon.root}' => __DIR__ . '/../..',
'{resources}' => defined('PATH_RESOURCES') ? PATH_RESOURCES : __DIR__ . '/../../resources',
'{root}' => defined('PATH_ROOT') ? PATH_ROOT : __DIR__ . '/../..'
];
}

/**
* Adds a default path to look for the .md files
*/
public function addDefaultPath(string $path) : void
{
foreach([
'{silicon.root}' => __DIR__ . '/../..',
] as $key => $value) {
foreach($this->getPathVars() as $key => $value) {
$path = str_replace($key, $value, $path);
}

Expand All @@ -71,11 +87,7 @@ public function addDefaultPath(string $path) : void
*/
public function setDefaultOutputPath(string $path) : void
{
$resourcePath = defined('PATH_RESOURCES') ? PATH_RESOURCES : __DIR__ . '/../../resources';

foreach([
'{resources}' => $resourcePath
] as $key => $value) {
foreach($this->getPathVars() as $key => $value) {
$path = str_replace($key, $value, $path);
}

Expand Down Expand Up @@ -171,7 +183,9 @@ public function execute()
$symbolData = $this->convertSymbolsToArray($symbols);
$json = json_encode($symbolData, JSON_PRETTY_PRINT);

$this->cli->json($symbolData);
if ($this->cli->arguments->get('print')) {
$this->cli->json($symbolData);
}

// wrire to file
if (!file_put_contents($outputPath, $json)) {
Expand Down

0 comments on commit 8bca5ce

Please sign in to comment.