Skip to content

Commit

Permalink
Making the output more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Jul 7, 2023
1 parent 2c981d3 commit e00bfab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/Commands/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function configure() {
* @inheritDoc
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
$io = $this->getIO();
$config = App::getConfig();
$root = $input->getOption( 'root' );
$build_steps = $config->getBuildCommands( $input->getOption( 'dev' ) );
Expand All @@ -35,21 +36,22 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
chdir( $root );
}

$output->writeln( '<comment>Running build steps...</comment>' );
$io->writeln( '<comment>Running build steps...</comment>' );
foreach ( $build_steps as $step ) {
$bail_on_failure = true;
if ( strpos( $step, '@' ) === 0 ) {
$bail_on_failure = false;
$step = substr( $step, 1 );
}
$output->writeln( "* {$step}..." );
$io->section( "> <fg=cyan>{$step}</>" );
system( $step, $result );
$io->newLine();

if ( $result ) {
$output->writeln( "[FAIL] Build step failed: {$step}" );
$io->writeln( "[FAIL] Build step failed: {$step}" );

if ( $bail_on_failure ) {
$output->writeln( "<fg=red>Exiting...</>" );
$io->writeln( "<fg=red>Exiting...</>" );
return $result;
}
}
Expand All @@ -59,7 +61,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
chdir( $config->getWorkingDir() );
}

$output->writeln( 'Build complete.' );
$io->writeln( '<info>Build complete.</info>' );
return 0;
}
}
23 changes: 13 additions & 10 deletions src/Commands/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected function configure() {
* @inheritDoc
*/
protected function execute( InputInterface $input, OutputInterface $output ) {
$io = $this->getIO();
$application = $this->getApplication();
if ( ! $application ) {
throw new BaseException( 'Could not run pup.' );
Expand All @@ -37,17 +38,17 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
$failures = [];

if ( $collection->count() === 0 ) {
$output->writeln( '📣 The .puprc does not have any checks configured.' );
$output->writeln( '💡 If you would like to use the defaults, simply remove the "<comment>checks</comment>" property in <comment>.puprc</comment>.' );
$io->writeln( '📣 The .puprc does not have any checks configured.' );
$io->writeln( '💡 If you would like to use the defaults, simply remove the "<comment>checks</comment>" property in <comment>.puprc</comment>.' );

$output->writeln( '' );
$output->writeln( 'If you would like to use one of the default checks, add one or more of the following to the "<comment>checks</comment>" property in your <comment>.puprc</comment>:' );
$output->writeln( ' "tbd": {}' );
$output->writeln( ' "version-conflict": {}' );
$io->writeln( '' );
$io->writeln( 'If you would like to use one of the default checks, add one or more of the following to the "<comment>checks</comment>" property in your <comment>.puprc</comment>:' );
$io->writeln( ' "tbd": {}' );
$io->writeln( ' "version-conflict": {}' );

$output->writeln( '' );
$output->writeln( 'If you would like to create your own check, take a look at the pup docs to learn how:' );
$output->writeln( ' https://github.com/stellarwp/pup' );
$io->writeln( '' );
$io->writeln( 'If you would like to create your own check, take a look at the pup docs to learn how:' );
$io->writeln( ' https://github.com/stellarwp/pup' );
return 0;
}

Expand All @@ -67,13 +68,15 @@ protected function execute( InputInterface $input, OutputInterface $output ) {

$should_bail_on_failure = $input->getOption( 'dev' ) ? $check->shouldBailOnFailureDev() : $check->shouldBailOnFailure();
if ( $should_bail_on_failure ) {

$io->writeln( "<fg=yellow>{$check->getSlug()}'s fail_method in <fg=cyan>.puprc</> is set to \"<fg=red>error</>\". Exiting...</>" );
return $results;
}
}
}

if ( ! empty( $failures ) ) {
$output->writeln( "\n<error>The following checks failed:</error> \n* " . implode( "\n* ", $failures ) );
$io->writeln( "\n<error>The following checks failed:</error> \n* " . implode( "\n* ", $failures ) );
}

return 0;
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/Checks/Tbd.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function checkConfigure(): void {
* @return int
*/
protected function checkExecute( InputInterface $input, Io $output ): int {
$this->writeln( '<comment>Checking for TBDs...</comment>' );
$output->section( '<comment>Checking for TBDs...</comment>' );

$root = $input->getOption( 'root' );

Expand Down Expand Up @@ -73,7 +73,6 @@ protected function checkExecute( InputInterface $input, Io $output ): int {

if ( $matched_lines ) {
$found_tbds = true;
$output->writeln( "<fg=red>TBDs have been found!</>" );
foreach ( $matched_lines as $file_path => $info ) {
$output->writeln( "<fg=cyan>{$file_path}</>" );
foreach ( $info['lines'] as $line_num => $line ) {
Expand All @@ -88,7 +87,7 @@ protected function checkExecute( InputInterface $input, Io $output ): int {
$output->writeln( '' );

if ( $found_tbds ) {
$output->writeln( '<error>TBDs found!</error>' );
$output->writeln( "<fg=red>TBDs have been found!</>" );
} else {
$output->writeln( '<info>Success! No TBDs found.</info>' );
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Checks/VersionConflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ protected function checkConfigure(): void {
* @return int
*/
protected function checkExecute( InputInterface $input, Io $output ): int {
$output->writeln( '<comment>Checking for version conflicts...</comment>' );
$output->section( '<comment>Checking for version conflicts...</comment>' );
$version_files = App::getConfig()->getVersionFiles();

$found_version_problem = false;
$versions = [];
$package_json_compatible_versions = [];

if ( empty( $version_files ) ) {
$output->writeln( '<fg=yellow>Skipping!</> There are no .paths.versions set in .puprc.' );
$output->writeln( '<fg=yellow>Skipping!</> There are no <fg=cyan>.paths.versions</> set in <fg=cyan>.puprc</>.' );
return 0;
}

Expand Down

0 comments on commit e00bfab

Please sign in to comment.