ChromaticHQ / usher

Custom Robo commands for use on PHP projects.
https://packagist.org/packages/chromatic/usher
11 stars 6 forks source link

Allow for configurable YAML output #214

Closed apotek closed 3 weeks ago

apotek commented 1 month ago

Description

Usher calls to Yaml Dumper currently use whatever (changing) defaults are provided by Symfony Yaml library. Yaml Dumper's dump method does allow for some control over how the resulting YAML is formatted, but we don't use any of those options in Usher, meaning we have no means of telling it what number of indentations we want, or how we want lists to be formatted.

Issue Owner

@apotek

Proposed Solution

Set up new config parameters for indentation, nesting-depth for inline yaml format, and a bitmask array that can be passed to the Dumper class.

Allow for our invocation of the dump method to use these configuration values when outputting the yaml. We will set Usher defaults in case the above mentioned configuration doesn't exist.

Example from SitesConfigTrait:

    protected function writeSitesConfig(array $sitesConfig): void
    {
+         [$inlineLevel, $indent, $dumpBits] = $this->config['yaml-opts'];
        ksort($sitesConfig);
-         file_put_contents($this->sitesConfigFile, Yaml::dump($sitesConfig));
+         file_put_contents($this->sitesConfigFile, Yaml::dump($sitesConfig, $inlineLevel, $indent, $dumpBits));
    }

Alternatives Considered

Additional Context

### Tasks