Skip to content

Commit

Permalink
added schema-filename-mask argument to console command
Browse files Browse the repository at this point in the history
  • Loading branch information
oliwierptak committed Nov 16, 2021
1 parent cead134 commit e244bc9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ You can either use it as composer dependency or as docker command.
-o [output-path] \
-nm [namespace] \
-nr [namespace-root] \
-p [schema-path-filter]
-p [schema-path-filter] \
-m [schema-filename-mask]
```
- with docker
```sh
Expand All @@ -120,7 +121,8 @@ You can either use it as composer dependency or as docker command.
-o [output-path] \
-nm [namespace] \
-nr [namespace-root] \
-p [schema-path-filter]
-p [schema-path-filter] \
-m [schema-filename-mask]
```


Expand Down Expand Up @@ -186,6 +188,13 @@ Each schema folder can contain multiple schema files, for example:
_Run `bin/popo generate -s tests/fixtures/ -p bundles -c tests/fixtures/bundles/project.config.yml` or `docker-popo generate -s tests/fixtures/ -p bundles -c tests/fixtures/bundles/project.config.yml` to generate files from this example._
### `[schema-filename-mask]`
Filename mask used to locate schema files when using `schema-path-filter`.
Default is `*.popo.yml`.
### Report Command
The `report` command shows list of defined / inherited properties.
Expand Down
30 changes: 25 additions & 5 deletions src/Popo/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class GenerateCommand extends AbstractCommand

public const OPTION_SCHEMA_CONFIG_FILENAME = 'schemaConfigFilename';

public const OPTION_SCHEMA_FILENAME_MASK = 'schemaFilenameMask';

public const OPTION_OUTPUT_PATH = 'outputPath';

public const OPTION_NAMESPACE = 'namespace';
Expand Down Expand Up @@ -74,7 +76,14 @@ protected function configure(): void
InputOption::VALUE_OPTIONAL,
'Path filter to match POPO schema files.',
null
)
),
new InputOption(
static::OPTION_SCHEMA_FILENAME_MASK,
'm',
InputOption::VALUE_OPTIONAL,
'Schema filename mask.',
'*.popo.yml'
),
]
);
}
Expand Down Expand Up @@ -116,14 +125,25 @@ protected function buildConfigurator(InputInterface $input): PopoConfigurator
$input->hasOption(static::OPTION_NAMESPACE) ? $input->getOption(static::OPTION_NAMESPACE) : null
)
->setNamespaceRoot(
$input->hasOption(static::OPTION_NAMESPACE_ROOT) ? $input->getOption(static::OPTION_NAMESPACE_ROOT) : null
$input->hasOption(static::OPTION_NAMESPACE_ROOT) ? $input->getOption(
static::OPTION_NAMESPACE_ROOT
) : null
)
->setSchemaPath((string)$input->getOption(static::OPTION_SCHEMA_PATH))
->setSchemaPath((string) $input->getOption(static::OPTION_SCHEMA_PATH))
->setSchemaPathFilter(
$input->hasOption(static::OPTION_SCHEMA_PATH_FILTER) ? $input->getOption(static::OPTION_SCHEMA_PATH_FILTER) : null
$input->hasOption(static::OPTION_SCHEMA_PATH_FILTER) ? $input->getOption(
static::OPTION_SCHEMA_PATH_FILTER
) : null
)
->setSchemaConfigFilename(
$input->hasOption(static::OPTION_SCHEMA_CONFIG_FILENAME) ? $input->getOption(static::OPTION_SCHEMA_CONFIG_FILENAME) : null
$input->hasOption(static::OPTION_SCHEMA_CONFIG_FILENAME) ? $input->getOption(
static::OPTION_SCHEMA_CONFIG_FILENAME
) : null
)
->setSchemaFilenameMask(
$input->hasOption(static::OPTION_SCHEMA_FILENAME_MASK) ? $input->getOption(
static::OPTION_SCHEMA_FILENAME_MASK
) : '*.popo.yml'
);
}
}
2 changes: 1 addition & 1 deletion src/Popo/Loader/SchemaLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function loadSchemaFiles(PopoConfigurator $configurator): array
$files = $this->fileLocator->locate(
$configurator->getSchemaPath(),
(string) $configurator->getSchemaPathFilter(),
$configurator->getSchemaFilename()
$configurator->getSchemaFilenameMask()
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Popo/PopoConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PopoConfigurator
protected ?string $outputPath = null;
protected string $schemaPath;
protected ?string $schemaPathFilter = null;
protected ?string $schemaFilename = '*.popo.yml';
protected ?string $schemaFilenameMask = '*.popo.yml';
protected ?string $schemaConfigFilename = null;

public function getNamespace(): ?string
Expand Down Expand Up @@ -74,14 +74,14 @@ public function setSchemaPathFilter(?string $schemaPathFilter): self
return $this;
}

public function getSchemaFilename(): ?string
public function getSchemaFilenameMask(): ?string
{
return $this->schemaFilename;
return $this->schemaFilenameMask;
}

public function setSchemaFilename(string $schemaFilename): self
public function setSchemaFilenameMask(string $schemaFilenameMask): self
{
$this->schemaFilename = $schemaFilename;
$this->schemaFilenameMask = $schemaFilenameMask;

return $this;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/suite/Popo/Command/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function test_command_params(): void
'--outputPath' => POPO_TESTS_DIR,
'--schemaPathFilter' => 'bundles',
'--schemaConfigFilename' => POPO_TESTS_DIR . 'fixtures/bundles/project.config.yml',
'--schemaFilenameMask' => '*.popo.yml',
]
);

Expand All @@ -53,6 +54,7 @@ public function test_generate_from_path(): void
'--outputPath' => POPO_TESTS_DIR,
'--schemaPathFilter' => 'bundles',
'--schemaConfigFilename' => POPO_TESTS_DIR . 'fixtures/bundles/project.config.yml',
'--schemaFilenameMask' => '*.popo.yml',
]
);

Expand Down
4 changes: 2 additions & 2 deletions tests/suite/Popo/PopoConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class PopoConfiguratorTest extends TestCase
{
public function testSetSchemaFilename()
{
$configurator = (new PopoConfigurator)->setSchemaFilename('*.schema.yml');
$configurator = (new PopoConfigurator)->setSchemaFilenameMask('*.schema.yml');

$this->assertEquals('*.schema.yml', $configurator->getSchemaFilename());
$this->assertEquals('*.schema.yml', $configurator->getSchemaFilenameMask());
}
}

0 comments on commit e244bc9

Please sign in to comment.