From 85b8b2e5f8adc3792f4b3338b3bdc887b76e8da1 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Fri, 23 May 2014 07:58:12 -0700 Subject: [PATCH] Make `arc shell-complete` more robust. Summary: Fixes T5122. Add some basic error handling to the `shell-complete` workflow. Test Plan: `arc shell-complete` no longer throws errors. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Maniphest Tasks: T5122 Differential Revision: https://secure.phabricator.com/D9268 --- src/workflow/ArcanistShellCompleteWorkflow.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/workflow/ArcanistShellCompleteWorkflow.php b/src/workflow/ArcanistShellCompleteWorkflow.php index 82cea04f..e4086bc5 100644 --- a/src/workflow/ArcanistShellCompleteWorkflow.php +++ b/src/workflow/ArcanistShellCompleteWorkflow.php @@ -30,8 +30,9 @@ EOTEXT public function getArguments() { return array( 'current' => array( - 'help' => 'Current term in the argument list being completed.', 'param' => 'cursor_position', + 'paramtype' => 'int', + 'help' => 'Current term in the argument list being completed.', ), '*' => 'argv', ); @@ -42,7 +43,6 @@ EOTEXT } public function run() { - $pos = $this->getArgument('current'); $argv = $this->getArgument('argv', array()); $argc = count($argv); @@ -50,6 +50,11 @@ EOTEXT $pos = $argc - 1; } + if ($pos > $argc) { + throw new ArcanistUsageException( + 'Specified position is greater than the number of arguments provided.'); + } + // Determine which revision control system the working copy uses, so we // can filter out commands and flags which aren't supported. If we can't // figure it out, just return all flags/commands. @@ -70,7 +75,7 @@ EOTEXT $arc_config = $this->getArcanistConfiguration(); - if ($pos == 1) { + if ($pos <= 1) { $workflows = $arc_config->buildAllWorkflows(); $complete = array(); @@ -81,8 +86,7 @@ EOTEXT $supported = $workflow->getSupportedRevisionControlSystems(); - $ok = (in_array('any', $supported)) || - (in_array($vcs, $supported)); + $ok = (in_array('any', $supported) || in_array($vcs, $supported)); if (!$ok) { continue; } @@ -146,7 +150,6 @@ EOTEXT } return 0; } else { - $output = array(); foreach ($arguments as $argument => $spec) { if ($argument == '*') { @@ -181,7 +184,7 @@ EOTEXT $branches = ipull($branches, 'name'); $output = $branches; } else { - $output = array("FILE"); + $output = array('FILE'); } }