Skip to content

Commit

Permalink
[FEATURE] Allow to call ConvertFormatCommand without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
nhovratov committed May 8, 2022
1 parent 2875237 commit 94d0d98
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Classes/Command/ConvertFormatCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ protected function configure(): void
'The paths configured in the extension configuration are used and will override existing files!' . LF .
'First argument is the source format and second argument is the target format.' . LF . LF .
'Usage: mask:convert [source] [target]' . LF . LF .
'Not providing the second argument leads to persisting the first format. This can be used for updating old configuration.' . LF . LF .
'Not providing any argument leads to persisting the current format. This can be used for updating old configuration.' . LF . LF .
'Available formats are: ' . $availableLoaders
);

$this->addArgument(
'source',
InputArgument::REQUIRED,
InputArgument::OPTIONAL,
'The source format'
);

Expand All @@ -64,17 +64,21 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$sourceLoader = $this->loaderRegistry->getLoader($input->getArgument('source'));
if ($input->hasArgument('source') && $input->getArgument('source') !== null) {
$sourceLoader = $this->loaderRegistry->getLoader($input->getArgument('source'));
} else {
$sourceLoader = $this->loaderRegistry->getActivateLoader();
}

if ($input->getArgument('target')) {
if ($input->hasArgument('target') && $input->getArgument('target') !== null) {
$targetLoader = $this->loaderRegistry->getLoader($input->getArgument('target'));
} else {
$targetLoader = $sourceLoader;
}

$targetLoader->write($sourceLoader->load());

// @todo Return error code, if write was not successfull.
// @todo Return error code, if write was not successfully executed.
return 0;
}
}

0 comments on commit 94d0d98

Please sign in to comment.