Skip to content

Commit 4b24a8c

Browse files
committed
added example from readme
1 parent f947924 commit 4b24a8c

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

examples/minimal.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 does nothing but print a version');
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+
echo $options->help();
23+
}
24+
}
25+
}
26+
// execute it
27+
$cli = new Minimal();
28+
$cli->run();

0 commit comments

Comments
 (0)