chore(namespace): rewirtten namspeace from app to GitContributionGraph.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GitContributionGraph\Command;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Attribute\Option;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
|
||||
|
||||
#[AsCommand(name: 'graph:contributions:refetch')]
|
||||
class RefetchContributionsCommand extends Command
|
||||
{
|
||||
private SymfonyStyle $io;
|
||||
public function __construct(
|
||||
#[AutowireIterator('app.provider')]
|
||||
private readonly iterable $providers,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function initialize(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->io = new SymfonyStyle($input, $output);
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
//TODO: check if its possible to add the preview with real strings from the providers.
|
||||
#[Option("(repeatable/comma-split, restricts to named provider(s), default = all configured", "provider", "p", "")]
|
||||
string $providers = ""
|
||||
) {
|
||||
$requested = $providers === '' ? null : explode(',', $providers);
|
||||
$byName = [];
|
||||
|
||||
foreach ($this->providers as $provider) {
|
||||
$byName[$provider->getName()] = $provider;
|
||||
}
|
||||
|
||||
if ($requested !== null) {
|
||||
foreach ($requested as $name) {
|
||||
if (!isset($byName[$name])) {
|
||||
$this->io->error("Unknown provider: {$name}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
$byName = array_intersect_key($byName, array_flip($requested));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user