Make output more configurable

Do only output success in the end.
Allow to output more info based on verbosity.
This commit is contained in:
danielsiepmann 2020-10-03 16:31:46 +02:00 committed by Daniel Siepmann
parent 9ec70df7bc
commit 93c22ce548
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4

View file

@ -54,25 +54,33 @@ class Command
$cutting = new Cutting($videoInfo); $cutting = new Cutting($videoInfo);
$this->io->title('Generating temp cutted video files.'); $this->executeStep('Generating temp cutted video files.');
foreach ($cutting->getCommandsForCutting() as $command) { foreach ($cutting->getCommandsForCutting() as $command) {
$this->runCommand($command); $this->runCommand($command);
} }
$this->io->title('Generating Metadata'); $this->executeStep(
$this->runCommand($cutting->getCommandForGeneratingMetadata()); 'Generating Metadata',
$cutting->getCommandForGeneratingMetadata()
);
$this->io->title('Generating Concat input file'); $this->executeStep(
$this->runCommand($cutting->getCommandForGeneratingConcatInputFile()); 'Generating Concat input file',
$cutting->getCommandForGeneratingConcatInputFile()
);
$this->io->title('Creating target folder'); $this->executeStep('Creating target folder');
$this->createTargetFolder($videoInfo); $this->createTargetFolder($videoInfo);
$this->io->title('Generating final video'); $this->executeStep(
$this->runCommand($cutting->getCommandForGeneratingVideo()); 'Generating final video',
$cutting->getCommandForGeneratingVideo()
);
$this->io->title('Cleanup'); $this->executeStep(
$this->runCommand($cutting->getCommandForCleanup()); 'Cleanup',
$cutting->getCommandForCleanup()
);
$this->io->success(sprintf( $this->io->success(sprintf(
'Generated video file "%s".', 'Generated video file "%s".',
@ -82,16 +90,29 @@ class Command
return 0; 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 private function runCommand(Process $command): void
{ {
if ($this->io->isVeryVerbose()) { if ($this->io->isVeryVerbose()) {
$this->io->comment('Executing command'); $this->io->writeln('Executing command');
$this->io->comment($command->getCommandLine()); $this->io->writeln($command->getCommandLine());
}
$command->run(function ($type, $buffer) { $command->run(function ($type, $buffer) {
$this->io->writeln($buffer); $this->io->writeln($buffer);
}); });
} else {
$command->run();
}
if (!$command->isSuccessful()) { if (!$command->isSuccessful()) {
throw new ProcessFailedException($command); throw new ProcessFailedException($command);