-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOption.php
48 lines (38 loc) · 971 Bytes
/
Option.php
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
<?php
namespace Lijinma;
class Option
{
public $flags = [];
public $desc;
public $long;
public $short;
public $optional = false;
public $required = false;
public function __construct($flags, $desc = '')
{
$this->rawFlags = $flags;
$this->flags = preg_split("/[\s,]+/", $flags);
$this->desc = $desc;
$this->addLongAndShort();
if (strpos($flags, '[') !== false) {
$this->optional = true;
} else if (strpos($flags, '<') !== false) {
$this->required = true;
}
}
public function addLongAndShort()
{
if (count($this->flags) > 1) {
$this->short = $this->flags[0];
$this->long = $this->flags[1];
}
}
public function getName()
{
return preg_replace('/--/', '', $this->long);
}
public function is($arg)
{
return $arg === $this->long || $arg === $this->short;
}
}