-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathsimple.php
More file actions
executable file
·55 lines (45 loc) · 1.43 KB
/
simple.php
File metadata and controls
executable file
·55 lines (45 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/php
<?php
namespace splitbrain\phpcli\examples;
require __DIR__ . '/../vendor/autoload.php';
use splitbrain\phpcli\CLI;
use splitbrain\phpcli\Options;
class Simple extends CLI
{
/**
* Register options and arguments on the given $options object
*
* @param Options $options
* @return void
*/
protected function setup(Options $options)
{
$options->setHelp('This is a simple example, not using any subcommands');
$options->registerOption('longflag', 'A flag that can also be set with a short option', 'l');
$options->registerOption('file', 'This option expects an argument.', 'f', 'filename');
$options->registerArgument('argument', 'Arguments can be required or optional. This one is optional', false);
}
/**
* Your main program
*
* Arguments and options have been parsed when this is run
*
* @param Options $options
* @return void
*/
protected function main(Options $options)
{
if ($options->getOpt('longflag')) {
$this->info("longflag was set");
} else {
$this->info("longflag was not set");
}
if ($options->getOpt('file')) {
$this->info("file was given as " . $options->getOpt('file'));
}
$this->info("Number of arguments: " . count($options->getArgs()));
$this->success("main finished");
}
}
$cli = new Simple();
$cli->run();