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())) {
35 foreach ($errs as $err) {
36 fprintf(STDERR
, "ERROR: %s\n", $err);
41 if ($this->args
["ngrok"]) {
42 $exec(Cli\Ngrok
::class);
44 if ($this->args
["initdb"]) {
45 $exec(Cli\Initdb
::class);
47 if ($this->args
["gen-models"]) {
48 $exec(Cli\GenModels
::class);
52 function getConfig() {
57 * Output command line help message
60 public function help($prog) {
61 printf("Usage:\n\n \$ %s", $prog);
66 foreach ($this->args
->getSpec() as $spec) {
67 if ($spec[3] & Args
::REQARG
) {
68 if ($spec[3] & Args
::REQUIRED
) {
79 printf(" [-%s]", implode("", array_column($flags, 0)));
81 foreach ($required as $req) {
82 printf(" -%s <arg>", $req[0]);
85 printf(" [-%s <arg>]", implode("|-", array_column($optional, 0)));
88 $spc = $this->args
->getSpec();
89 $max = $spc ?
max(array_map("strlen", array_column($spc, 1))) : 0;
91 foreach ($spc as $spec) {
92 if (isset($spec[0])) {
93 printf(" -%s|", $spec[0]);
97 printf("--%s ", $spec[1]);
98 if ($spec[3] & Args
::REQARG
) {
100 } elseif ($spec[3] & Args
::OPTARG
) {
105 printf("%s%s", str_repeat(" ", $max-strlen($spec[1])+
3*!isset($spec[0])), $spec[2]);
106 if ($spec[3] & Args
::REQUIRED
) {
107 printf(" (REQUIRED)");
109 if (isset($spec[4])) {
110 printf(" [%s]", $spec[4]);