File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/php
2+ <?php
3+ require __DIR__ . '/../vendor/autoload.php ' ;
4+ use splitbrain \phpcli \CLI ;
5+ use splitbrain \phpcli \Options ;
6+
7+ class Minimal extends CLI
8+ {
9+ // register options and arguments
10+ protected function setup (Options $ options )
11+ {
12+ $ options ->setHelp ('A very minimal example that prints a version or demos the logging ' );
13+ $ options ->registerOption ('version ' , 'print version ' , 'v ' );
14+ }
15+
16+ // implement your code
17+ protected function main (Options $ options )
18+ {
19+ if ($ options ->getOpt ('version ' )) {
20+ $ this ->info ('1.0.0 ' );
21+ } else {
22+ $ this ->debug ('This is a debug message ' );
23+ $ this ->info ('This is a info message ' );
24+ $ this ->notice ('This is a notice message ' );
25+ $ this ->success ('This is a success message ' );
26+ $ this ->warning ('This is a warning message ' );
27+ $ this ->error ('This is a error message ' );
28+ $ this ->critical ('This is a critical message ' );
29+ $ this ->alert ('This is a alert message ' );
30+ $ this ->emergency ('This is a emergency message ' );
31+ throw new \Exception ('Exception will be caught, too ' );
32+ }
33+ }
34+ }
35+ // execute it
36+ $ cli = new Minimal ();
37+ $ cli ->run ();
You can’t perform that action at this time.
0 commit comments