File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 1717
1818use Yannoff \Component \Console \Command ;
1919use Yannoff \Component \Console \Definition \Option ;
20+ use Yannoff \Component \Console \Exception \RuntimeException ;
2021use Yannoff \PhpCodeCompiler \Directory ;
2122use Yannoff \PhpCodeCompiler \PharBuilder ;
2223
@@ -54,8 +55,8 @@ public function execute()
5455 $ files = $ this ->getOption ('file ' ) ?? [];
5556 $ meta = $ this ->getOption ('meta ' ) ?? [];
5657
57- $ output = $ this ->getOption ( ' output ' );
58- $ main = $ this ->getOption ( ' main ' );
58+ $ main = $ this ->require ( ' main ' );
59+ $ output = $ this ->require ( ' output ' );
5960
6061 $ this
6162 ->initBuilder ($ main )
@@ -225,6 +226,26 @@ protected function fullpath(string $file): string
225226 return getcwd () . '/ ' . $ file ;
226227 }
227228
229+ /**
230+ * Try to get the required option, raise an exception if not set
231+ *
232+ * @param string $option The option name
233+ *
234+ * @return mixed
235+ *
236+ * @throws RuntimeException If the required option is not set
237+ */
238+ protected function require (string $ option )
239+ {
240+ $ value = $ this ->getOption ($ option );
241+
242+ if (null === $ value ) {
243+ throw new RuntimeException ("Mandatory option -- {$ option } is missing " );
244+ }
245+
246+ return $ value ;
247+ }
248+
228249 /**
229250 * Return the contents wrapped in a comments block
230251 *
You can’t perform that action at this time.
0 commit comments