Skip to content

Commit f74ec9c

Browse files
committed
add more setting for flags parse
1 parent 6b0881c commit f74ec9c

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed

src/Flag/Flags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function parse(array $args = null): array
9191
}
9292

9393
$this->parsed = true;
94-
$this->rawArgs = $this->args = $args;
94+
$this->rawFlags = $this->args = $args;
9595

9696
while (true) {
9797
[$goon, $status] = $this->parseOne();

src/Flag/SFlags.php

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,73 @@ class SFlags extends AbstractObj
2828
// List of option allow array values.
2929
'arrayOpts' => [], // ['names', 'status']
3030
// Special short style
31-
// posix: -abc will expand: -a -b -c
32-
// unix: -abc will expand: -a=bc
33-
'shortStyle' => 'posix',
31+
// gnu: `-abc` will expand: `-a -b -c`
32+
// posix: `-abc` will expand: `-a=bc`
33+
'shortStyle' => 'posix',
3434
];
3535

3636
/**
37+
* Special short style
38+
* gnu: `-abc` will expand: `-a -b -c`
39+
* posix: `-abc` will expand: `-a=bc`
40+
*
41+
* @var string
42+
*/
43+
private $shortStyle = 'posix';
44+
45+
/**
46+
* Whether stop parse option on found unknown option
47+
*
48+
* @var bool
49+
*/
50+
private $stopOnUnknown = true;
51+
52+
/**
53+
* Whether parse the remaining args {@see $rawArgs}.
54+
*
55+
* eg: 'arg=value' -> [arg => value]
56+
*
57+
* @var bool
58+
*/
59+
private $parseRawArgs = true;
60+
61+
/**
62+
* Parsed options
63+
*
64+
* @var array
65+
*/
66+
private $opts = [];
67+
68+
/**
69+
* Parsed arguments
70+
*
71+
* @var array
72+
*/
73+
private $args = [];
74+
75+
/**
76+
* Parse options by pre-defined
77+
*
78+
* ```php
79+
* // element format:
80+
* // - k-v: k is option, v is value type
81+
* // - v: v is option, type is string.
82+
* $defines = [
83+
* 's,long', // use default type: string
84+
* // option => value type,
85+
* 's,long' => string,
86+
* 's' => bool,
87+
* 'long' => int,
88+
* 'long' => array, // TODO int[], string[]
89+
* ];
90+
* ```
91+
*
3792
* @param array $rawArgs
38-
* @param array $settings
93+
* @param array $defines
3994
*
4095
* @return array
4196
*/
42-
public function parse(array $rawArgs, array $settings = []): array
97+
public function parseDefined(array $rawArgs, array $defines, array $settings = []): array
4398
{
4499
$this->setSettings($settings);
45100
}

src/Flag/Traits/FlagParsingTrait.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,34 @@ trait FlagParsingTrait
2323
private $stopOnArg = true;
2424

2525
/**
26-
* The remaining args on option parsed
26+
* The raw input flags
2727
*
2828
* @var array
2929
*/
30-
private $args = [];
30+
protected $rawFlags = [];
3131

3232
/**
33-
* The raw input args
33+
* The remaining args.
34+
* After on option parsed from {@see $rawFlags}
3435
*
3536
* @var array
3637
*/
37-
private $rawArgs = [];
38+
protected $rawArgs = [];
3839

3940
/**
4041
* @return array
4142
*/
42-
public function getArgs(): array
43+
public function getRawArgs(): array
4344
{
44-
return $this->args;
45+
return $this->rawArgs;
4546
}
4647

4748
/**
4849
* @return array
4950
*/
50-
public function getRawArgs(): array
51+
public function getRawFlags(): array
5152
{
52-
return $this->rawArgs;
53+
return $this->rawFlags;
5354
}
5455

5556
/**

0 commit comments

Comments
 (0)