]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Modularize Arcanist settings, let users pick between ambiguous interpretations of...
authorepriestley <git@epriestley.com>
Wed, 23 Nov 2016 16:18:02 +0000 (08:18 -0800)
committerepriestley <git@epriestley.com>
Wed, 23 Nov 2016 21:25:40 +0000 (13:25 -0800)
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

src/__phutil_library_map__.php
src/browse/workflow/ArcanistBrowseWorkflow.php
src/configuration/ArcanistSetting.php [new file with mode: 0644]
src/configuration/ArcanistSettings.php

index e21738f70e776ba05489f5dd3ed5d7e69e66c1c8..bc0c78ccddbaed09ce6c614ba5801e0715e322a1 100644 (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',
index 0e146bd78c3889f082f2da0d26694d7d412488cc..dbe82423a2cc25d8f3788be4a18593f46432df7f 100644 (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();
     }
 
diff --git a/src/configuration/ArcanistSetting.php b/src/configuration/ArcanistSetting.php
new file mode 100644 (file)
index 0000000..ff32239
--- /dev/null
@@ -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();
+  }
+
+}
index f87fb356946c9f6443e2bd56508b0b078b43a51b..2ecd1abd4800d933df7665e3790575a12d0be3fc 100644 (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) {