parent
c40a14aba0
commit
c1c36475de
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace jrosset\CliProgram;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Application;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper methods
|
||||||
|
*/
|
||||||
|
abstract class CliHelper {
|
||||||
|
/**
|
||||||
|
* Get the “error” output if exists, else the output itself
|
||||||
|
*
|
||||||
|
* @param OutputInterface $output The output
|
||||||
|
*
|
||||||
|
* @return OutputInterface The “error” output if exists, else the output itself
|
||||||
|
*/
|
||||||
|
public static final function getErrorOutput (OutputInterface $output): OutputInterface {
|
||||||
|
return $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of a command class
|
||||||
|
*
|
||||||
|
* @param Application $application The application
|
||||||
|
* @param class-string<Command> $commandClass The command class
|
||||||
|
*
|
||||||
|
* @return string|null The command name ; Null if not found
|
||||||
|
*/
|
||||||
|
public static final function getCommandNameFromClass (Application $application, string $commandClass): ?string {
|
||||||
|
foreach ($application->all() as $possibleCommand) {
|
||||||
|
if ($possibleCommand::class == $commandClass) {
|
||||||
|
return $possibleCommand->getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace jrosset\CliProgram;
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class for command/application output
|
|
||||||
*/
|
|
||||||
abstract class OutputHelper {
|
|
||||||
/**
|
|
||||||
* Get the “error” output if exists, else the output itself
|
|
||||||
*
|
|
||||||
* @param OutputInterface $output The output
|
|
||||||
*
|
|
||||||
* @return OutputInterface The “error” output if exists, else the output itself
|
|
||||||
*/
|
|
||||||
public static final function getErrorOutput (OutputInterface $output): OutputInterface {
|
|
||||||
return $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue