Push can now push json file
This commit is contained in:
@ -15,7 +15,8 @@ class Push extends Console\Command\Command
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addOption('configurations', 'c', Console\Input\InputOption::VALUE_REQUIRED | Console\Input\InputOption::VALUE_IS_ARRAY, 'Job configuration, must be in valid JSON format');
|
||||
$this->addOption('configurations', 'c', Console\Input\InputOption::VALUE_REQUIRED | Console\Input\InputOption::VALUE_IS_ARRAY, 'Job configuration options array, each job configuration must be in valid JSON format');
|
||||
$this->addOption('file', 'f', Console\Input\InputOption::VALUE_REQUIRED, 'Path to jobs configuration file with JSON array');
|
||||
}
|
||||
|
||||
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
|
||||
@ -23,8 +24,8 @@ class Push extends Console\Command\Command
|
||||
$io = new Console\Style\SymfonyStyle($input, $output);
|
||||
$io->title("Pushing job");
|
||||
|
||||
$configurations = $input->getOption('configurations');
|
||||
if ($configurations === null) {
|
||||
$configurations = $this->getConfigurations($input);
|
||||
if (count($configurations) === 0) {
|
||||
$io->error('Missing configurations');
|
||||
return self::FAILURE;
|
||||
}
|
||||
@ -46,4 +47,21 @@ class Push extends Console\Command\Command
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getConfigurations(Console\Input\InputInterface $input): array
|
||||
{
|
||||
$configurations = [];
|
||||
$filePath = $input->getOption('file');
|
||||
if ($filePath !== null and file_exists($filePath)) {
|
||||
$json = file_get_contents($filePath);
|
||||
if (json_validate($json)) {
|
||||
$configurations = array_map(fn($configArray) => json_encode($configArray), json_decode($json, true));
|
||||
}
|
||||
}
|
||||
$configOptions = $input->getOption('configurations');
|
||||
if ($configOptions !== null) {
|
||||
$configurations = array_merge($configurations, array_filter($configOptions, fn($config) => json_validate($config)));
|
||||
}
|
||||
return $configurations;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user