Skip to content

Commit 4f97899

Browse files
committed
update readme for use sflags
1 parent 944a443 commit 4f97899

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@ $fs->parse($rawFlags);
4646
// or use
4747
// $fs->parseDefined($flags, $optRules, $argRules);
4848

49-
vdump($fs->getRawArgs(), $fs->getOpts());
49+
vdump($fs->getOpts(), $fs->getRawArgs());
5050
```
5151

5252
Output:
5353

5454
```text
55-
array(1) {
56-
[0]=> string(4) "arg0"
57-
}
5855
array(3) {
5956
["name"]=> string(6) "inhere"
6057
["tag"]=> array(3) {
@@ -64,6 +61,9 @@ array(3) {
6461
}
6562
["f"]=> bool(true)
6663
}
64+
array(1) {
65+
[0]=> string(4) "arg0"
66+
}
6767
```
6868

6969
### Parse CLI Input
@@ -80,14 +80,15 @@ $scriptFile = array_shift($rawFlags);
8080
$optRules = [
8181
// some option rules
8282
'name', // string
83-
'age' => 'int,required', // set required
83+
'age' => 'int,required', // set required
8484
'tag,t' => FlagType::ARRAY,
85-
'f' => FlagType::BOOL,
85+
'f' => FlagType::BOOL,
8686
];
8787
$argRules = [
8888
// some argument rules
8989
'string',
90-
'array',
90+
// set name
91+
'arrArg' => 'array',
9192
];
9293

9394
$fs = SFlags::new()->parseDefined($rawFlags, $optRules, $argRules);
@@ -102,15 +103,6 @@ php example/sflags-demo.php --name inhere --age 99 --tag go -t php -t java -f ar
102103
Output:
103104

104105
```text
105-
$ php example/sflags-demo.php --name inhere --age 99 --tag go -t php -t java -f arg0 arr0 arr1 21-08-24 - 19:38:01
106-
CALL ON /Users/inhere/.kite/vendor/toolkit/pflag/example/sflags-demo.php(44):
107-
array(2) {
108-
[0]=> string(4) "arg0"
109-
[1]=> array(2) {
110-
[0]=> string(4) "arr0"
111-
[1]=> string(4) "arr1"
112-
}
113-
}
114106
array(4) {
115107
["name"]=> string(6) "inhere"
116108
["age"]=> int(99)
@@ -121,7 +113,13 @@ array(4) {
121113
}
122114
["f"]=> bool(true)
123115
}
124-
116+
array(2) {
117+
[0]=> string(4) "arg0"
118+
[1]=> array(2) {
119+
[0]=> string(4) "arr0"
120+
[1]=> string(4) "arr1"
121+
}
122+
}
125123
```
126124

127125
### Get Value
@@ -135,6 +133,16 @@ $name = $fs->getOption('name'); // string(inhere)
135133
$tags = $fs->getOption('tags'); // array{"php", "go", "java"}
136134
```
137135

136+
**Arguments**
137+
138+
```php
139+
$arg0 = $fs->getArg(0); // string(arg0)
140+
// get an array arg
141+
$arrArg = $fs->getArg(1); // array{"arr0", "arr1"}
142+
// use name
143+
$arrArg = $fs->getArg('arrArg'); // array{"arr0", "arr1"}
144+
```
145+
138146
## License
139147

140148
[MIT](LICENSE)

example/sflags-demo.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
$argRules = [
2929
// some argument rules
3030
'string',
31-
'array',
31+
// set name
32+
'arrArg' => 'array',
3233
];
3334

3435
$fs = SFlags::new();
@@ -40,6 +41,8 @@
4041

4142
vdump(
4243
// $fs->getRawArgs(),
43-
$fs->getArgs(),
44-
$fs->getOpts()
44+
$fs->getOpts(),
45+
$fs->getArgs()
4546
);
47+
48+
// vdump($fs->getArg('arrArg'));

src/SFlags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function parse(array $rawFlags): self
350350
}
351351
}
352352

353-
// collect arguments.
353+
// collect remaining arguments.
354354
$this->rawArgs[] = $p;
355355
}
356356

test/FlagsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Toolkit\PFlag\Flags;
1414
use Toolkit\PFlag\Flag\Option;
1515
use Toolkit\PFlag\FlagType;
16-
use function vdump;
1716

1817
/**
1918
* Class FlagsTest

0 commit comments

Comments
 (0)