Changeset View
Changeset View
Standalone View
Standalone View
src/browse/workflow/ArcanistBrowseWorkflow.php
Show First 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | foreach ($refs as $ref) { | ||||
$zero_hits[] = $ref; | $zero_hits[] = $ref; | ||||
} else if (count($uris) == 1) { | } else if (count($uris) == 1) { | ||||
$open_uris[] = $ref; | $open_uris[] = $ref; | ||||
} else { | } else { | ||||
$many_hits[] = $ref; | $many_hits[] = $ref; | ||||
} | } | ||||
} | } | ||||
$pick_map = array(); | |||||
$pick_selection = null; | |||||
$pick_id = 0; | |||||
if ($many_hits) { | if ($many_hits) { | ||||
foreach ($many_hits as $ref) { | foreach ($many_hits as $ref) { | ||||
$token = $ref->getToken(); | $token = $ref->getToken(); | ||||
if (strlen($token)) { | if (strlen($token)) { | ||||
$message = pht('Argument "%s" is ambiguous.', $token); | $message = pht('Argument "%s" is ambiguous.', $token); | ||||
} else { | } else { | ||||
$message = pht('Default behavior is ambiguous.'); | $message = pht('Default behavior is ambiguous.'); | ||||
} | } | ||||
$this->writeWarn(pht('AMBIGUOUS'), $message); | $this->writeWarn(pht('AMBIGUOUS'), $message); | ||||
} | } | ||||
$table = id(new PhutilConsoleTable()) | $is_single_ref = (count($refs) == 1); | ||||
->addColumn('argument', array('title' => pht('Argument'))) | |||||
$table = id(new PhutilConsoleTable()); | |||||
if ($is_single_ref) { | |||||
$table->addColumn('pick', array('title' => pht('Pick'))); | |||||
} else { | |||||
$table->addColumn('argument', array('title' => pht('Argument'))); | |||||
} | |||||
$table | |||||
->addColumn('type', array('title' => pht('Type'))) | ->addColumn('type', array('title' => pht('Type'))) | ||||
->addColumn('uri', array('title' => pht('URI'))); | ->addColumn('uri', array('title' => pht('URI'))); | ||||
foreach ($many_hits as $ref) { | foreach ($many_hits as $ref) { | ||||
$token_display = $ref->getToken(); | $token_display = $ref->getToken(); | ||||
if (!strlen($token)) { | if (!strlen($token)) { | ||||
$token_display = pht('<default>'); | $token_display = pht('<default>'); | ||||
} | } | ||||
foreach ($ref->getURIs() as $uri) { | foreach ($ref->getURIs() as $uri) { | ||||
++$pick_id; | |||||
$pick_map[$pick_id] = $uri; | |||||
$row = array( | $row = array( | ||||
'pick' => $pick_id, | |||||
'argument' => $token_display, | 'argument' => $token_display, | ||||
'type' => $uri->getType(), | 'type' => $uri->getType(), | ||||
'uri' => $uri->getURI(), | 'uri' => $uri->getURI(), | ||||
); | ); | ||||
$table->addRow($row); | $table->addRow($row); | ||||
} | } | ||||
} | } | ||||
$table->draw(); | $table->draw(); | ||||
if ($is_single_ref) { | |||||
$pick_selection = phutil_console_select( | |||||
pht('Which URI do you want to open?'), | |||||
1, | |||||
$pick_id); | |||||
$open_uris[] = $ref; | |||||
} else { | |||||
$this->writeInfo( | $this->writeInfo( | ||||
pht('CHOOSE'), | pht('CHOOSE'), | ||||
pht('Use "--types" to select between alternatives.')); | pht('Use "--types" to select between alternatives.')); | ||||
} | } | ||||
} | |||||
// If anything failed to resolve, this is also an error. | // If anything failed to resolve, this is also an error. | ||||
if ($zero_hits) { | if ($zero_hits) { | ||||
foreach ($zero_hits as $ref) { | foreach ($zero_hits as $ref) { | ||||
echo tsprintf( | echo tsprintf( | ||||
"%s\n", | "%s\n", | ||||
pht( | pht( | ||||
'Unable to resolve argument "%s".', | 'Unable to resolve argument "%s".', | ||||
$ref->getToken())); | $ref->getToken())); | ||||
} | } | ||||
foreach ($loaders as $loader) { | foreach ($loaders as $loader) { | ||||
$loader->didFailToLoadBrowseURIRefs($refs); | $loader->didFailToLoadBrowseURIRefs($refs); | ||||
} | } | ||||
} | } | ||||
$uris = array(); | $uris = array(); | ||||
foreach ($open_uris as $ref) { | foreach ($open_uris as $ref) { | ||||
$ref_uri = head($ref->getURIs()); | $ref_uris = $ref->getURIs(); | ||||
if (count($ref_uris) > 1) { | |||||
foreach ($ref_uris as $uri_key => $uri) { | |||||
if ($pick_map[$pick_selection] !== $uri) { | |||||
unset($ref_uris[$uri_key]); | |||||
} | |||||
} | |||||
} | |||||
$ref_uri = head($ref_uris); | |||||
$uris[] = $ref_uri->getURI(); | $uris[] = $ref_uri->getURI(); | ||||
} | } | ||||
$this->openURIsInBrowser($uris); | $this->openURIsInBrowser($uris); | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } |