18
18
use Yannoff \Component \Console \Command ;
19
19
use Yannoff \Component \Console \Definition \Option ;
20
20
use Yannoff \Component \Console \Exception \RuntimeException ;
21
+ use Yannoff \Component \Console \IO \Output \Verbosity ;
21
22
use Yannoff \PhpCodeCompiler \Contents ;
22
23
use Yannoff \PhpCodeCompiler \Directory ;
23
24
use Yannoff \PhpCodeCompiler \PharBuilder ;
@@ -37,13 +38,16 @@ public function configure()
37
38
{
38
39
$ this
39
40
->setHelp ('PHP Code compiler - Phar executable compiling utility ' )
41
+ // Compiling options
40
42
->addOption ('main ' , 'e ' , Option::VALUE , 'Set the PHAR stub \'s main entrypoint script ' )
41
43
->addOption ('dir ' , 'd ' , Option::MULTI , 'Add directory contents ("-d $dir") optionally filtered on a specific file extension ("$dir:$extension") ' )
42
44
->addOption ('file ' , 'f ' , Option::MULTI , 'Add a single file to the archive ' )
43
45
->addOption ('meta ' , 'm ' , Option::MULTI , 'Add a metadata property (eg: "-m $key:$value") ' )
44
46
->addOption ('output ' , 'o ' , Option::VALUE , 'Set the compiled archive output name ' )
45
47
->addOption ('banner ' , 'b ' , Option::VALUE , 'Load legal notice from the given banner file ' )
46
48
->addOption ('shebang-less ' , '' , Option::FLAG , 'Produce a stub deprived of the shebang directive ' )
49
+ // Global options
50
+ ->addOption ('quiet ' , 'q ' , Option::FLAG , 'Set output verbosity level to INFO instead of DEBUG ' )
47
51
;
48
52
}
49
53
@@ -63,6 +67,9 @@ public function execute()
63
67
64
68
$ shebang = (!$ this ->getOption ('shebang-less ' ));
65
69
70
+ $ quiet = $ this ->getOption ('quiet ' );
71
+ $ this ->setVerbosity ($ quiet ? Verbosity::INFO : Verbosity::DEBUG );
72
+
66
73
$ this
67
74
->initBuilder ($ main )
68
75
->addFiles ($ files )
@@ -119,7 +126,7 @@ protected function addFile(string $file)
119
126
{
120
127
$ fullpath = $ this ->fullpath ($ file );
121
128
122
- $ this ->info ('+ ' . $ file , 'grey ' );
129
+ $ this ->debug ('+ ' . $ file , 'grey ' );
123
130
124
131
// Only minify pure PHP source files, other files such as
125
132
// code templates for instance, should be left as-is
@@ -180,7 +187,7 @@ protected function addMetadata(array $definitions): self
180
187
foreach ($ definitions as $ definition ) {
181
188
list ($ name , $ value ) = explode (': ' , $ definition );
182
189
$ this ->info ("Adding <strong> $ name</strong> metadata property " );
183
- $ this ->info ("-> $ name: $ value " , 'grey ' );
190
+ $ this ->debug ("-> $ name: $ value " , 'grey ' );
184
191
$ this ->builder ->addMetadata ($ name , $ value );
185
192
}
186
193
@@ -200,7 +207,7 @@ protected function setNotice(string $banner = null): self
200
207
$ this ->info ("Loading banner contents from <strong> $ banner</strong> file... " );
201
208
$ header = $ this ->commentOut ($ banner );
202
209
203
- $ this ->info (implode ("\n" , $ header ), 'grey ' );
210
+ $ this ->debug (implode ("\n" , $ header ), 'grey ' );
204
211
$ this ->builder ->setBanner ($ header );
205
212
}
206
213
@@ -282,17 +289,44 @@ protected function commentOut(string $banner): array
282
289
/**
283
290
* Print a message to STDERR, optionally encapsulated by styling tags
284
291
*
285
- * @param string $message
286
- * @param string $tag
292
+ * @param string $message Console-flavour pre-formatted message
293
+ * @param int $level Verbosity level (defaults to ERROR)
294
+ * @param string $tag Optional encapsulating style tags name
287
295
*
288
296
* @return self
289
297
*/
290
- protected function info (string $ message , string $ tag = '' ): self
298
+ protected function print (string $ message, int $ level = Verbosity:: ERROR , string $ tag = '' ): self
291
299
{
292
300
$ otag = $ tag ? "< $ tag> " : '' ;
293
301
$ ctag = $ tag ? "</ $ tag> " : '' ;
294
- $ this ->error (sprintf ('%s%s%s ' , $ otag , $ message , $ ctag ));
302
+ $ this ->dmesg (sprintf ('%s%s%s ' , $ otag , $ message , $ ctag ), $ level );
295
303
296
304
return $ this ;
297
305
}
306
+
307
+ /**
308
+ * Print an INFO message to standard error
309
+ *
310
+ * @param string $message Pre-formatted info message
311
+ * @param string $tag Optional styling tag name
312
+ *
313
+ * @return self
314
+ */
315
+ protected function info (string $ message , string $ tag = '' ): self
316
+ {
317
+ return $ this ->print ($ message , Verbosity::INFO , $ tag );
318
+ }
319
+
320
+ /**
321
+ * Print a DEBUG message to standard error
322
+ *
323
+ * @param string $message Pre-formatted debug message
324
+ * @param string $tag Optional styling tag name
325
+ *
326
+ * @return self
327
+ */
328
+ protected function debug (string $ message , string $ tag = '' ): self
329
+ {
330
+ return $ this ->print ($ message , Verbosity::DEBUG , $ tag );
331
+ }
298
332
}
0 commit comments