/** * Create a compact version of basic usage instructions * * @param boolean $header Whether or not to include a help header * @return string */ public function createUsage($header = false) { $ret = ''; $bools = []; $others = []; foreach ($this->fields as $field) { $name = $field->getName(); $usage = $this->createFieldUsage($field); if ($field instanceof BooleanField) { $bools[$name] = $usage; } else { $others[$name] = $usage; } } $opts = array_merge(array_values($bools), array_values($others)); $cmd = Cli::getScriptName(); $maxWidth = min(Cli::getWidth(), 78); if ($header === true) { $ret .= $this->createHeader('usage'); $tmp = " {$cmd}"; } else { $tmp = "usage: {$cmd}"; } $indent = strlen($tmp); foreach ($opts as $opt) { if (strlen($tmp) + strlen($opt) >= $maxWidth) { $ret .= "{$tmp}\n"; $tmp = str_pad('', $indent, ' ') . " {$opt}"; } else { $tmp .= " {$opt}"; } } $ret .= $tmp; return $ret; }