15 * @var \pharext\Cli\Args
19 function __construct(Config
$config, Args
$args) {
20 $this->config
= $config;
24 function __invoke($argc, array $argv, callable
$exec) {
25 $prog = array_shift($argv);
26 foreach ($this->args
->parse(--$argc, $argv) as $error) {
30 if ($this->args
["help"] ||
!array_filter($this->args
->toArray())) {
31 //var_dump($this->args->toArray(), $this->args[0]);
36 foreach ($errs as $err) {
37 fprintf(STDERR
, "ERROR: %s\n", $err);
42 switch($this->args
[0]) {
44 $exec(Cli\Ngrok
::class);
47 $exec(Cli\Initdb
::class);
50 $exec(Cli\GenModels
::class);
55 function getConfig() {
60 * Output command line help message
63 public function help($prog) {
64 return print new Args\
Help($prog, $this->args
);
65 printf("Usage:\n\n \$ %s", $prog);
70 foreach ($this->args
->getSpec() as $spec) {
71 if ($spec[3] & Args
::REQARG
) {
72 if ($spec[3] & Args
::REQUIRED
) {
83 printf(" [-%s]", implode("", array_column($flags, 0)));
85 foreach ($required as $req) {
86 printf(" -%s <arg>", $req[0]);
89 printf(" [-%s <arg>]", implode("|-", array_column($optional, 0)));
92 $spc = $this->args
->getSpec();
93 $max = $spc ?
max(array_map("strlen", array_column($spc, 1))) : 0;
95 foreach ($spc as $spec) {
96 if (isset($spec[0])) {
97 printf(" -%s|", $spec[0]);
101 printf("--%s ", $spec[1]);
102 if ($spec[3] & Args
::REQARG
) {
104 } elseif ($spec[3] & Args
::OPTARG
) {
109 printf("%s%s", str_repeat(" ", $max-strlen($spec[1])+
3*!isset($spec[0])), $spec[2]);
110 if ($spec[3] & Args
::REQUIRED
) {
111 printf(" (REQUIRED)");
113 if (isset($spec[4])) {
114 printf(" [%s]", $spec[4]);