FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
php-cli/examples/simple.php at master · splitbrain/php-cli · GitHub
splitbrain
/
php-cli
Public
Notifications
You must be signed in to change notification settings
Fork
40
Star
179
Code
Issues
1
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
php-cli
/
examples
/
simple.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
55 lines (45 loc) · 1.43 KB
Breadcrumbs
php-cli
/
examples
/
simple.php
Copy path
File metadata and controls
executable file
·
55 lines (45 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
();
Back
|
FazBrowse Home
|
New Git URL