Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime: Add controls on mandatory options #10

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use Yannoff\Component\Console\Command;
use Yannoff\Component\Console\Definition\Option;
use Yannoff\Component\Console\Exception\RuntimeException;
use Yannoff\PhpCodeCompiler\Directory;
use Yannoff\PhpCodeCompiler\PharBuilder;

Expand Down Expand Up @@ -54,8 +55,8 @@ public function execute()
$files = $this->getOption('file') ?? [];
$meta = $this->getOption('meta') ?? [];

$output = $this->getOption('output');
$main = $this->getOption('main');
$main = $this->require('main');
$output = $this->require('output');

$this
->initBuilder($main)
Expand Down Expand Up @@ -225,6 +226,26 @@ protected function fullpath(string $file): string
return getcwd() . '/' . $file;
}

/**
* Try to get the required option, raise an exception if not set
*
* @param string $option The option name
*
* @return mixed
*
* @throws RuntimeException If the required option is not set
*/
protected function require(string $option)
{
$value = $this->getOption($option);

if (null === $value) {
throw new RuntimeException("Mandatory option --{$option} is missing");
}

return $value;
}

/**
* Return the contents wrapped in a comments block
*
Expand Down