Skip to content

Commit

Permalink
Add custom checks to the output of pup help
Browse files Browse the repository at this point in the history
  • Loading branch information
test committed Jul 21, 2023
1 parent 36e713f commit 12dff04
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Commands/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use StellarWP\Pup\App;
use StellarWP\Pup\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;

class Help extends Command {
Expand Down Expand Up @@ -84,6 +86,40 @@ protected function printCommandList(): void {
}
}

$application = $this->getApplication();
if ( $application ) {
$command = $application->find( 'list' );
$arguments = [];

$buffer = new BufferedOutput();

$command_input = new ArrayInput( $arguments );
$command->run( $command_input, $buffer );

preg_match_all( '/check:([^\s\t]+)(.*)$/m', $buffer->fetch(), $matches );

$command_parts = [];
if ( ! empty( $matches[1] ) ) {
$command_parts = $matches[1];
}

foreach ( $command_parts as $command_part ) {
if ( ! isset( $command_part ) ) {
continue;
}

$command_part = trim( $command_part );

if ( in_array( $command_part, [ 'tbd', 'version-conflict' ], true ) ) {
continue;
}

$command = '<fg=yellow>check:' . $command_part . '</>';

$commands[ $command ] = [ $command, 'Custom check' ];
}
}

ksort( $commands );

$io->table(
Expand Down

0 comments on commit 12dff04

Please sign in to comment.