1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-01 10:20:58 +01:00

Modularize Arcanist settings, let users pick between ambiguous interpretations of arc browse ...

Summary:
Ref T10895. This modularizes Arcanist settings, but doesn't do anything with them yet.

When users type `arc browse X`, and only provide one "X", and there are several ways to interpret it, prompt them to choose one.

Test Plan: Created a file named `T234`, ran `arc browse T234`, was prompted to interpret it as an object or a path.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10895

Differential Revision: https://secure.phabricator.com/D16928
This commit is contained in:
epriestley 2016-11-23 08:18:02 -08:00
parent 909668082e
commit dc4e0f788d
4 changed files with 101 additions and 7 deletions

View file

@ -350,6 +350,7 @@ phutil_register_library_map(array(
'ArcanistSemicolonSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistSemicolonSpacingXHPASTLinterRule.php',
'ArcanistSemicolonSpacingXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistSemicolonSpacingXHPASTLinterRuleTestCase.php',
'ArcanistSetConfigWorkflow' => 'workflow/ArcanistSetConfigWorkflow.php',
'ArcanistSetting' => 'configuration/ArcanistSetting.php',
'ArcanistSettings' => 'configuration/ArcanistSettings.php',
'ArcanistShellCompleteWorkflow' => 'workflow/ArcanistShellCompleteWorkflow.php',
'ArcanistSingleLintEngine' => 'lint/engine/ArcanistSingleLintEngine.php',
@ -787,6 +788,7 @@ phutil_register_library_map(array(
'ArcanistSemicolonSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistSemicolonSpacingXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistSetConfigWorkflow' => 'ArcanistWorkflow',
'ArcanistSetting' => 'Phobject',
'ArcanistSettings' => 'Phobject',
'ArcanistShellCompleteWorkflow' => 'ArcanistWorkflow',
'ArcanistSingleLintEngine' => 'ArcanistLintEngine',

View file

@ -154,6 +154,9 @@ EOTEXT
}
}
$pick_map = array();
$pick_selection = null;
$pick_id = 0;
if ($many_hits) {
foreach ($many_hits as $ref) {
$token = $ref->getToken();
@ -166,8 +169,17 @@ EOTEXT
$this->writeWarn(pht('AMBIGUOUS'), $message);
}
$table = id(new PhutilConsoleTable())
->addColumn('argument', array('title' => pht('Argument')))
$is_single_ref = (count($refs) == 1);
$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('uri', array('title' => pht('URI')));
@ -178,7 +190,11 @@ EOTEXT
}
foreach ($ref->getURIs() as $uri) {
++$pick_id;
$pick_map[$pick_id] = $uri;
$row = array(
'pick' => $pick_id,
'argument' => $token_display,
'type' => $uri->getType(),
'uri' => $uri->getURI(),
@ -190,9 +206,17 @@ EOTEXT
$table->draw();
$this->writeInfo(
pht('CHOOSE'),
pht('Use "--types" to select between alternatives.'));
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(
pht('CHOOSE'),
pht('Use "--types" to select between alternatives.'));
}
}
// If anything failed to resolve, this is also an error.
@ -212,7 +236,17 @@ EOTEXT
$uris = array();
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();
}

View file

@ -0,0 +1,48 @@
<?php
abstract class ArcanistSetting
extends Phobject {
final public function getSettingKey() {
return $this->getPhobjectClassConstant('SETTINGKEY', 32);
}
public function getAliases() {
return array();
}
abstract public function getHelp();
abstract public function getType();
public function getExample() {
return null;
}
final public function getLegacyDictionary() {
$result = array(
'type' => $this->getType(),
'help' => $this->getHelp(),
);
$example = $this->getExample();
if ($example !== null) {
$result['example'] = $example;
}
$aliases = $this->getAliases();
if ($aliases) {
$result['legacy'] = head($aliases);
}
return $result;
}
final public static function getAllSettings() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getSettingKey')
->setSortMethod('getSettingKey')
->execute();
}
}

View file

@ -3,7 +3,7 @@
final class ArcanistSettings extends Phobject {
private function getOptions() {
return array(
$legacy_builtins = array(
'default' => array(
'type' => 'string',
'help' => pht(
@ -175,6 +175,16 @@ final class ArcanistSettings extends Phobject {
'Configured command aliases. Use "arc alias" to define aliases.'),
),
);
$settings = ArcanistSetting::getAllSettings();
foreach ($settings as $key => $setting) {
$settings[$key] = $setting->getLegacyDictionary();
}
$results = $settings + $legacy_builtins;
ksort($results);
return $results;
}
private function getOption($key) {