From 93c22ce54893e4931684d6e3912068aa95b89e3e Mon Sep 17 00:00:00 2001 From: danielsiepmann Date: Sat, 3 Oct 2020 16:31:46 +0200 Subject: [PATCH] Make output more configurable Do only output success in the end. Allow to output more info based on verbosity. --- src/Command.php | 53 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/src/Command.php b/src/Command.php index d4818d8..5a52ea2 100644 --- a/src/Command.php +++ b/src/Command.php @@ -54,25 +54,33 @@ class Command $cutting = new Cutting($videoInfo); - $this->io->title('Generating temp cutted video files.'); + $this->executeStep('Generating temp cutted video files.'); foreach ($cutting->getCommandsForCutting() as $command) { $this->runCommand($command); } - $this->io->title('Generating Metadata'); - $this->runCommand($cutting->getCommandForGeneratingMetadata()); + $this->executeStep( + 'Generating Metadata', + $cutting->getCommandForGeneratingMetadata() + ); - $this->io->title('Generating Concat input file'); - $this->runCommand($cutting->getCommandForGeneratingConcatInputFile()); + $this->executeStep( + 'Generating Concat input file', + $cutting->getCommandForGeneratingConcatInputFile() + ); - $this->io->title('Creating target folder'); + $this->executeStep('Creating target folder'); $this->createTargetFolder($videoInfo); - $this->io->title('Generating final video'); - $this->runCommand($cutting->getCommandForGeneratingVideo()); + $this->executeStep( + 'Generating final video', + $cutting->getCommandForGeneratingVideo() + ); - $this->io->title('Cleanup'); - $this->runCommand($cutting->getCommandForCleanup()); + $this->executeStep( + 'Cleanup', + $cutting->getCommandForCleanup() + ); $this->io->success(sprintf( 'Generated video file "%s".', @@ -82,16 +90,29 @@ class Command return 0; } + private function executeStep(string $name, Process $command = null): void + { + if ($this->io->isVerbose()) { + $this->io->writeln($name); + } + + if ($command instanceof Process) { + $this->runCommand($command); + } + } + private function runCommand(Process $command): void { if ($this->io->isVeryVerbose()) { - $this->io->comment('Executing command'); - $this->io->comment($command->getCommandLine()); - } + $this->io->writeln('Executing command'); + $this->io->writeln($command->getCommandLine()); - $command->run(function ($type, $buffer) { - $this->io->writeln($buffer); - }); + $command->run(function ($type, $buffer) { + $this->io->writeln($buffer); + }); + } else { + $command->run(); + } if (!$command->isSuccessful()) { throw new ProcessFailedException($command);