-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5: Add
software
command
- Loading branch information
Showing
6 changed files
with
137 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Internal\DLoad\Command; | ||
|
||
use Internal\DLoad\Bootstrap; | ||
use Internal\DLoad\Service\Container; | ||
use Internal\DLoad\Service\Logger; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class Base extends Command | ||
{ | ||
protected Logger $logger; | ||
|
||
protected Container $container; | ||
|
||
protected function execute( | ||
InputInterface $input, | ||
OutputInterface $output, | ||
): int { | ||
$this->logger = new Logger($output); | ||
$this->container = $container = Bootstrap::init()->withConfig( | ||
xml: \dirname(__DIR__, 2) . '/dload.xml', | ||
inputOptions: $input->getOptions(), | ||
inputArguments: $input->getArguments(), | ||
environment: \getenv(), | ||
)->finish(); | ||
$container->set($input, InputInterface::class); | ||
$container->set($output, OutputInterface::class); | ||
$container->set(new SymfonyStyle($input, $output), StyleInterface::class); | ||
$container->set($this->logger); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Internal\DLoad\Command; | ||
|
||
use Internal\DLoad\Module\Common\Config\Embed\Software; | ||
use Internal\DLoad\Module\Downloader\SoftwareCollection; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[AsCommand( | ||
name: 'software', | ||
description: 'List available software', | ||
)] | ||
final class ListSoftware extends Base | ||
Check failure on line 21 in src/Command/ListSoftware.php GitHub Actions / psalm (ubuntu-latest, 8.2, locked)PropertyNotSetInConstructor
Check failure on line 21 in src/Command/ListSoftware.php GitHub Actions / psalm (ubuntu-latest, 8.2, locked)PropertyNotSetInConstructor
|
||
{ | ||
protected function execute( | ||
InputInterface $input, | ||
OutputInterface $output, | ||
): int { | ||
parent::execute($input, $output); | ||
|
||
/** @var SoftwareCollection $registry */ | ||
$registry = $this->container->get(SoftwareCollection::class); | ||
|
||
$output->writeln('There are <options=bold>' . $registry->count() . '</> software available:'); | ||
$output->writeln(''); | ||
|
||
/** @var Software $software */ | ||
foreach ($registry->getIterator() as $software) { | ||
$output->writeln("<fg=green;options=bold>{$software->getId()}</> $software->name"); | ||
|
||
foreach ($software->repositories as $repo) { | ||
$output->writeln("<fg=blue>{$repo->type}: {$repo->uri}</>"); | ||
} | ||
|
||
$software->description and $output->writeln("<fg=gray>" . \wordwrap($software->description, 78) . "</>"); | ||
$output->writeln(''); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters