array( 'help' => 'Print detailed information about each command.', ), '*' => 'command', ); } public function run() { $arc_config = $this->getArcanistConfiguration(); $workflows = $arc_config->buildAllWorkflows(); ksort($workflows); $target = null; if ($this->getArgument('command')) { $target = reset($this->getArgument('command')); if (empty($workflows[$target])) { throw new ArcanistUsageException( "Unrecognized command '{$target}'. Try 'arc help'."); } } $cmdref = array(); foreach ($workflows as $command => $workflow) { if ($target && $target != $command) { continue; } if (!$target && !$this->getArgument('full')) { $cmdref[] = $workflow->getCommandSynopses(); continue; } $optref = array(); $arguments = $workflow->getArguments(); $config_arguments = $arc_config->getCustomArgumentsForCommand($command); // This juggling is to put the extension arguments after the normal // arguments, and make sure the normal arguments aren't overwritten. ksort($arguments); ksort($config_arguments); foreach ($config_arguments as $argument => $spec) { if (empty($arguments[$argument])) { $arguments[$argument] = $spec; } } foreach ($arguments as $argument => $spec) { if ($argument == '*') { continue; } if (!empty($spec['hide'])) { continue; } if (isset($spec['param'])) { if (isset($spec['short'])) { $optref[] = phutil_console_format( " __--%s__ __%s__, __-%s__ __%s__", $argument, $spec['param'], $spec['short'], $spec['param']); } else { $optref[] = phutil_console_format( " __--%s__ __%s__", $argument, $spec['param']); } } else { if (isset($spec['short'])) { $optref[] = phutil_console_format( " __--%s__, __-%s__", $argument, $spec['short']); } else { $optref[] = phutil_console_format( " __--%s__", $argument); } } if (isset($config_arguments[$argument])) { $optref[] = " (This is a custom option for this ". "project.)"; } if (isset($spec['supports'])) { $optref[] = " Supports: ". implode(', ', $spec['supports']); } if (isset($spec['help'])) { $docs = $spec['help']; } else { $docs = 'This option is not documented.'; } $docs = phutil_console_wrap($docs, 14); $optref[] = " {$docs}\n"; } if ($optref) { $optref = implode("\n", $optref); $optref = "\n\n".$optref; } else { $optref = "\n"; } $cmdref[] = $workflow->getCommandSynopses()."\n". $workflow->getCommandHelp(). $optref; } $cmdref = implode("\n\n", $cmdref); if ($target) { echo "\n".$cmdref."\n"; return; } $self = 'arc'; $description = ($this->getArgument('full') ? "This help file provides a detailed command reference." : "Run 'arc help --full' to get detailed command reference."); echo phutil_console_format(<<getArgument('full')) { return; } echo phutil_console_format(<<