mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 08:52:39 +01:00
Make "arc <workflow> --help" work again for workflows which haven't updated yet
Summary: See <https://discourse.phabricator-community.org/t/help-is-no-longer-present-for-arc-subcommands-in-todays-stable/3786>. The "--help" flag ends up falling through to the old "arcanist.php", where it becomes lost. Catch it earlier so "arc diff --help" prints diff help, for instance. Test Plan: Ran `arc help diff`, `arc diff --help`, `arc --help diff`, and similar commands for updated workflows; got help. Differential Revision: https://secure.phabricator.com/D21168
This commit is contained in:
parent
68f050bd14
commit
bf76fa547d
5 changed files with 74 additions and 59 deletions
|
@ -77,6 +77,7 @@ final class PhutilArgumentParser extends Phobject {
|
||||||
private $tagline;
|
private $tagline;
|
||||||
private $synopsis;
|
private $synopsis;
|
||||||
private $workflows;
|
private $workflows;
|
||||||
|
private $helpWorkflows;
|
||||||
private $showHelp;
|
private $showHelp;
|
||||||
private $requireArgumentTerminator = false;
|
private $requireArgumentTerminator = false;
|
||||||
private $sawTerminator = false;
|
private $sawTerminator = false;
|
||||||
|
@ -449,11 +450,13 @@ final class PhutilArgumentParser extends Phobject {
|
||||||
|
|
||||||
$flow = $corrected;
|
$flow = $corrected;
|
||||||
} else {
|
} else {
|
||||||
|
if (!$this->showHelp) {
|
||||||
$this->raiseUnknownWorkflow($flow, $corrected);
|
$this->raiseUnknownWorkflow($flow, $corrected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$workflow = $this->workflows[$flow];
|
$workflow = idx($this->workflows, $flow);
|
||||||
|
|
||||||
if ($this->showHelp) {
|
if ($this->showHelp) {
|
||||||
// Make "cmd flow --help" behave like "cmd help flow", not "cmd help".
|
// Make "cmd flow --help" behave like "cmd help flow", not "cmd help".
|
||||||
|
@ -471,6 +474,10 @@ final class PhutilArgumentParser extends Phobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$workflow) {
|
||||||
|
$this->raiseUnknownWorkflow($flow, $corrected);
|
||||||
|
}
|
||||||
|
|
||||||
$this->argv = array_values($argv);
|
$this->argv = array_values($argv);
|
||||||
|
|
||||||
if ($workflow->shouldParsePartial()) {
|
if ($workflow->shouldParsePartial()) {
|
||||||
|
@ -633,6 +640,12 @@ final class PhutilArgumentParser extends Phobject {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setHelpWorkflows(array $help_workflows) {
|
||||||
|
$help_workflows = mpull($help_workflows, null, 'getName');
|
||||||
|
$this->helpWorkflows = $help_workflows;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getWorkflows() {
|
public function getWorkflows() {
|
||||||
return $this->workflows;
|
return $this->workflows;
|
||||||
}
|
}
|
||||||
|
@ -684,11 +697,16 @@ final class PhutilArgumentParser extends Phobject {
|
||||||
$out[] = null;
|
$out[] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->workflows) {
|
$workflows = $this->helpWorkflows;
|
||||||
|
if ($workflows === null) {
|
||||||
|
$workflows = $this->workflows;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($workflows) {
|
||||||
$has_help = false;
|
$has_help = false;
|
||||||
$out[] = $this->format('**%s**', pht('WORKFLOWS'));
|
$out[] = $this->format('**%s**', pht('WORKFLOWS'));
|
||||||
$out[] = null;
|
$out[] = null;
|
||||||
$flows = $this->workflows;
|
$flows = $workflows;
|
||||||
ksort($flows);
|
ksort($flows);
|
||||||
foreach ($flows as $workflow) {
|
foreach ($flows as $workflow) {
|
||||||
if ($workflow->getName() == 'help') {
|
if ($workflow->getName() == 'help') {
|
||||||
|
@ -739,7 +757,12 @@ final class PhutilArgumentParser extends Phobject {
|
||||||
|
|
||||||
$indent = ($show_details ? 0 : 6);
|
$indent = ($show_details ? 0 : 6);
|
||||||
|
|
||||||
$workflow = idx($this->workflows, strtolower($workflow_name));
|
$workflows = $this->helpWorkflows;
|
||||||
|
if ($workflows === null) {
|
||||||
|
$workflows = $this->workflows;
|
||||||
|
}
|
||||||
|
|
||||||
|
$workflow = idx($workflows, strtolower($workflow_name));
|
||||||
if (!$workflow) {
|
if (!$workflow) {
|
||||||
$out[] = $this->indent(
|
$out[] = $this->indent(
|
||||||
$indent,
|
$indent,
|
||||||
|
|
|
@ -2,17 +2,6 @@
|
||||||
|
|
||||||
final class PhutilHelpArgumentWorkflow extends PhutilArgumentWorkflow {
|
final class PhutilHelpArgumentWorkflow extends PhutilArgumentWorkflow {
|
||||||
|
|
||||||
private $runtime;
|
|
||||||
|
|
||||||
public function setRuntime($runtime) {
|
|
||||||
$this->runtime = $runtime;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRuntime() {
|
|
||||||
return $this->runtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function didConstruct() {
|
protected function didConstruct() {
|
||||||
$this->setName('help');
|
$this->setName('help');
|
||||||
$this->setExamples(<<<EOHELP
|
$this->setExamples(<<<EOHELP
|
||||||
|
@ -39,47 +28,6 @@ EOHELP
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$with = $args->getArg('help-with-what');
|
$with = $args->getArg('help-with-what');
|
||||||
|
|
||||||
$runtime = $this->getRuntime();
|
|
||||||
if ($runtime) {
|
|
||||||
$toolset = $runtime->getToolset();
|
|
||||||
if ($toolset->getToolsetKey() === 'arc') {
|
|
||||||
$workflows = $args->getWorkflows();
|
|
||||||
|
|
||||||
$legacy = array();
|
|
||||||
|
|
||||||
$legacy[] = new ArcanistCloseRevisionWorkflow();
|
|
||||||
$legacy[] = new ArcanistCommitWorkflow();
|
|
||||||
$legacy[] = new ArcanistCoverWorkflow();
|
|
||||||
$legacy[] = new ArcanistDiffWorkflow();
|
|
||||||
$legacy[] = new ArcanistExportWorkflow();
|
|
||||||
$legacy[] = new ArcanistGetConfigWorkflow();
|
|
||||||
$legacy[] = new ArcanistSetConfigWorkflow();
|
|
||||||
$legacy[] = new ArcanistInstallCertificateWorkflow();
|
|
||||||
$legacy[] = new ArcanistLandWorkflow();
|
|
||||||
$legacy[] = new ArcanistLintersWorkflow();
|
|
||||||
$legacy[] = new ArcanistLintWorkflow();
|
|
||||||
$legacy[] = new ArcanistListWorkflow();
|
|
||||||
$legacy[] = new ArcanistPatchWorkflow();
|
|
||||||
$legacy[] = new ArcanistPasteWorkflow();
|
|
||||||
$legacy[] = new ArcanistTasksWorkflow();
|
|
||||||
$legacy[] = new ArcanistTodoWorkflow();
|
|
||||||
$legacy[] = new ArcanistUnitWorkflow();
|
|
||||||
$legacy[] = new ArcanistWhichWorkflow();
|
|
||||||
|
|
||||||
foreach ($legacy as $workflow) {
|
|
||||||
// If this workflow has been updated but not removed from the list
|
|
||||||
// above yet, just skip it.
|
|
||||||
if ($workflow instanceof ArcanistArcWorkflow) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$workflows[] = $workflow->newLegacyPhutilWorkflow();
|
|
||||||
}
|
|
||||||
|
|
||||||
$args->setWorkflows($workflows);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$with) {
|
if (!$with) {
|
||||||
$args->printHelpAndExit();
|
$args->printHelpAndExit();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -162,6 +162,9 @@ final class ArcanistRuntime {
|
||||||
|
|
||||||
// TOOLSETS: Some day, stop falling through to the old "arc" runtime.
|
// TOOLSETS: Some day, stop falling through to the old "arc" runtime.
|
||||||
|
|
||||||
|
$help_workflows = $this->getHelpWorkflows($phutil_workflows);
|
||||||
|
$args->setHelpWorkflows($help_workflows);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $args->parseWorkflowsFull($phutil_workflows);
|
return $args->parseWorkflowsFull($phutil_workflows);
|
||||||
} catch (ArcanistMissingArgumentTerminatorException $terminator_exception) {
|
} catch (ArcanistMissingArgumentTerminatorException $terminator_exception) {
|
||||||
|
@ -869,4 +872,41 @@ final class ArcanistRuntime {
|
||||||
return $this->toolset;
|
return $this->toolset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getHelpWorkflows(array $workflows) {
|
||||||
|
if ($this->getToolset()->getToolsetKey() === 'arc') {
|
||||||
|
$legacy = array();
|
||||||
|
|
||||||
|
$legacy[] = new ArcanistCloseRevisionWorkflow();
|
||||||
|
$legacy[] = new ArcanistCommitWorkflow();
|
||||||
|
$legacy[] = new ArcanistCoverWorkflow();
|
||||||
|
$legacy[] = new ArcanistDiffWorkflow();
|
||||||
|
$legacy[] = new ArcanistExportWorkflow();
|
||||||
|
$legacy[] = new ArcanistGetConfigWorkflow();
|
||||||
|
$legacy[] = new ArcanistSetConfigWorkflow();
|
||||||
|
$legacy[] = new ArcanistInstallCertificateWorkflow();
|
||||||
|
$legacy[] = new ArcanistLandWorkflow();
|
||||||
|
$legacy[] = new ArcanistLintersWorkflow();
|
||||||
|
$legacy[] = new ArcanistLintWorkflow();
|
||||||
|
$legacy[] = new ArcanistListWorkflow();
|
||||||
|
$legacy[] = new ArcanistPatchWorkflow();
|
||||||
|
$legacy[] = new ArcanistPasteWorkflow();
|
||||||
|
$legacy[] = new ArcanistTasksWorkflow();
|
||||||
|
$legacy[] = new ArcanistTodoWorkflow();
|
||||||
|
$legacy[] = new ArcanistUnitWorkflow();
|
||||||
|
$legacy[] = new ArcanistWhichWorkflow();
|
||||||
|
|
||||||
|
foreach ($legacy as $workflow) {
|
||||||
|
// If this workflow has been updated but not removed from the list
|
||||||
|
// above yet, just skip it.
|
||||||
|
if ($workflow instanceof ArcanistArcWorkflow) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$workflows[] = $workflow->newLegacyPhutilWorkflow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $workflows;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,11 @@ final class ArcanistWorkflowArgument
|
||||||
$spec['param'] = $parameter;
|
$spec['param'] = $parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$help = $this->getHelp();
|
||||||
|
if ($help !== null) {
|
||||||
|
$spec['help'] = $help;
|
||||||
|
}
|
||||||
|
|
||||||
return $spec;
|
return $spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,7 @@ final class ArcanistHelpWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newPhutilWorkflow() {
|
public function newPhutilWorkflow() {
|
||||||
return id(new PhutilHelpArgumentWorkflow())
|
return new PhutilHelpArgumentWorkflow();
|
||||||
->setRuntime($this->getRuntime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsToolset(ArcanistToolset $toolset) {
|
public function supportsToolset(ArcanistToolset $toolset) {
|
||||||
|
|
Loading…
Reference in a new issue