refactor(Installer): move class to create command

This commit is contained in:
Jérémy Dufraisse 2023-03-19 09:25:28 +01:00
parent 0d565af13d
commit 9e6d84e085
6 changed files with 76 additions and 3 deletions

View File

@ -28,7 +28,8 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Seacms\\ComposerInstaller\\": "src" "Seacms\\ComposerInstaller\\": "src/installer/",
"Seacms\\Command\\": "src/commands/"
} }
}, },
"extra": { "extra": {

63
src/commands/Command.php Normal file
View File

@ -0,0 +1,63 @@
<?php
/**
* SPDX-License-Identifier: EUPL-1.2
* Authors: see /README.md
*/
namespace Seacms\Command;
use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command to lauch tests from command line accross all seacms dependencies
*/
class Command extends BaseCommand
{
/**
* set name
*/
protected function configure() {
$this->setName('seacms-test');
$this
// the short description shown while running "php bin/console list"
->setDescription('Testing seacms from command line')
// the full command description shown when running the command with
// the "--help" option
->setHelp("Test seacms via command line.\n".
"(Only if phpunit available)\n")
->addOption('toto', '', InputOption::VALUE_NONE, 'Display toto text')
->addOption('text', 't', InputOption::VALUE_REQUIRED, 'Display the text')
;
}
/**
* execute the command
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<info>Testing seacms</info>');
$totoOption = $input->getOption('toto');
$textOption = $input->getOption('test');
if ($totoOption){
$output->writeln('toto');
}
if ($textOption){
$output->writeln($textOption);
}
return Command::SUCCESS;
}
}

View File

@ -9,11 +9,12 @@ namespace Seacms\ComposerInstaller;
use Composer\Composer; use Composer\Composer;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface; use Composer\Plugin\PluginInterface;
use TopFloor\ComposerCleanupVcsDirs\Plugin as TopFloorPlugin; use TopFloor\ComposerCleanupVcsDirs\Plugin as TopFloorPlugin;
if (class_exists(TopFloorPlugin::class,true)){ if (class_exists(TopFloorPlugin::class,true)){
abstract class ParentPlugin extends TopFloorPlugin abstract class ParentPlugin extends TopFloorPlugin implements Capable
{ {
/** /**
* const to test if TopFloorPlugin * const to test if TopFloorPlugin
@ -22,7 +23,7 @@ if (class_exists(TopFloorPlugin::class,true)){
protected const IS_TOP_FLOOR_PLUGIN = true; protected const IS_TOP_FLOOR_PLUGIN = true;
} }
} else { } else {
abstract class ParentPlugin implements PluginInterface abstract class ParentPlugin implements PluginInterface, Capable
{ {
/** /**

View File

@ -215,4 +215,12 @@ class Plugin extends ParentPlugin
} }
throw new Exception("Correspondance not found"); throw new Exception("Correspondance not found");
} }
/* === implements Capable === */
public function getCapabilities()
{
return [
'Composer\Plugin\Capability\CommandProvider' => 'Seacms\\Command\\Command',
];
}
} }