Page MenuHomePhabricator

D10706.diff
No OneTemporary

D10706.diff

diff --git a/src/workflow/ArcanistLintersWorkflow.php b/src/workflow/ArcanistLintersWorkflow.php
--- a/src/workflow/ArcanistLintersWorkflow.php
+++ b/src/workflow/ArcanistLintersWorkflow.php
@@ -11,7 +11,7 @@
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
- **linters** [__options__]
+ **linters** [__options__] [__name__]
EOTEXT
);
}
@@ -21,6 +21,8 @@
Supports: cli
List the available and configured linters, with information about
what they do and which versions are installed.
+
+ if __name__ is provided, the linter with that name will be displayed.
EOTEXT
));
}
@@ -30,6 +32,14 @@
'verbose' => array(
'help' => pht('Show detailed information, including options.'),
),
+ 'search' => array(
+ 'param' => 'search',
+ 'repeat' => true,
+ 'help' => pht(
+ 'Search for linters. Search is case-insensitive, and is performed'.
+ 'against name and description of each linter.'),
+ ),
+ '*' => 'exact',
);
}
@@ -46,46 +56,7 @@
$built = array();
}
- // Note that an engine can emit multiple linters of the same class to run
- // different rulesets on different groups of files, so these linters do not
- // necessarily have unique classes or types.
- $groups = array();
- foreach ($built as $linter) {
- $groups[get_class($linter)][] = $linter;
- }
-
- $linter_info = array();
- foreach ($linters as $key => $linter) {
- $installed = idx($groups, $key, array());
- $exception = null;
-
- if ($installed) {
- $status = 'configured';
- try {
- $version = head($installed)->getVersion();
- } catch (Exception $ex) {
- $status = 'error';
- $exception = $ex;
- }
- } else {
- $status = 'available';
- $version = null;
- }
-
- $linter_info[$key] = array(
- 'short' => $linter->getLinterConfigurationName(),
- 'class' => get_class($linter),
- 'status' => $status,
- 'version' => $version,
- 'name' => $linter->getInfoName(),
- 'uri' => $linter->getInfoURI(),
- 'description' => $linter->getInfoDescription(),
- 'exception' => $exception,
- 'options' => $linter->getLinterConfigurationOptions(),
- );
- }
-
- $linter_info = isort($linter_info, 'short');
+ $linter_info = $this->getLintersInfo($linters, $built);
$status_map = $this->getStatusMap();
$pad = ' ';
@@ -96,6 +67,34 @@
'error' => 'red',
);
+ $is_verbose = $this->getArgument('verbose');
+ $exact = $this->getArgument('exact');
+ $search_terms = $this->getArgument('search');
+
+ if ($exact && $search_terms) {
+ throw new ArcanistUsageException(
+ 'Specify either search expression or exact name');
+ }
+
+ if ($exact) {
+ $linter_info = $this->findExactNames($linter_info, $exact);
+ if (!$linter_info) {
+ $console->writeOut(
+ "%s\n",
+ pht(
+ 'No match found. Try `%s %s` to search for a linter.',
+ 'arc linters --search',
+ $exact[0]));
+ return;
+ }
+ $is_verbose = true;
+ }
+
+ if ($search_terms) {
+ $linter_info = $this->filterByNames($linter_info, $search_terms);
+ }
+
+
foreach ($linter_info as $key => $linter) {
$status = $linter['status'];
$color = $color_map[$status];
@@ -119,63 +118,65 @@
$print_tail = true;
}
- $version = $linter['version'];
- $uri = $linter['uri'];
- if ($version || $uri) {
- $console->writeOut("\n");
- $print_tail = true;
- }
-
- if ($version) {
- $console->writeOut("%s%s **%s**\n", $pad, pht('Version'), $version);
- }
-
- if ($uri) {
- $console->writeOut("%s__%s__\n", $pad, $linter['uri']);
- }
+ if ($is_verbose) {
+ $version = $linter['version'];
+ $uri = $linter['uri'];
+ if ($version || $uri) {
+ $console->writeOut("\n");
+ $print_tail = true;
+ }
- $description = $linter['description'];
- if ($description) {
- $console->writeOut(
- "\n%s\n",
- phutil_console_wrap($linter['description'], strlen($pad)));
- $print_tail = true;
- }
+ if ($version) {
+ $console->writeOut("%s%s **%s**\n", $pad, pht('Version'), $version);
+ }
- $options = $linter['options'];
- if ($options && $this->getArgument('verbose')) {
- $console->writeOut(
- "\n%s**%s**\n\n",
- $pad,
- pht('Configuration Options'));
+ if ($uri) {
+ $console->writeOut("%s__%s__\n", $pad, $linter['uri']);
+ }
- $last_option = last_key($options);
- foreach ($options as $option => $option_spec) {
+ $description = $linter['description'];
+ if ($description) {
$console->writeOut(
- "%s__%s__ (%s)\n",
- $pad,
- $option,
- $option_spec['type']);
+ "\n%s\n",
+ phutil_console_wrap($linter['description'], strlen($pad)));
+ $print_tail = true;
+ }
+ $options = $linter['options'];
+ if ($options) {
$console->writeOut(
- "%s\n",
- phutil_console_wrap(
- $option_spec['help'],
- strlen($pad) + 2));
-
- if ($option != $last_option) {
- $console->writeOut("\n");
+ "\n%s**%s**\n\n",
+ $pad,
+ pht('Configuration Options'));
+
+ $last_option = last_key($options);
+ foreach ($options as $option => $option_spec) {
+ $console->writeOut(
+ "%s__%s__ (%s)\n",
+ $pad,
+ $option,
+ $option_spec['type']);
+
+ $console->writeOut(
+ "%s\n",
+ phutil_console_wrap(
+ $option_spec['help'],
+ strlen($pad) + 2));
+
+ if ($option != $last_option) {
+ $console->writeOut("\n");
+ }
}
+ $print_tail = true;
}
- $print_tail = true;
- }
- if ($print_tail) {
- $console->writeOut("\n");
+ if ($print_tail) {
+ $console->writeOut("\n");
+ }
}
}
- if (!$this->getArgument('verbose')) {
+ if (!$is_verbose) {
$console->writeOut(
"%s\n",
pht('(Run `%s` for more details.)', 'arc linters --verbose'));
@@ -212,4 +213,80 @@
return $text_map;
}
+ private function getLintersInfo(array $linters, array $built) {
+ // Note that an engine can emit multiple linters of the same class to run
+ // different rulesets on different groups of files, so these linters do not
+ // necessarily have unique classes or types.
+ $groups = array();
+ foreach ($built as $linter) {
+ $groups[get_class($linter)][] = $linter;
+ }
+
+ $linter_info = array();
+ foreach ($linters as $key => $linter) {
+ $installed = idx($groups, $key, array());
+ $exception = null;
+
+ if ($installed) {
+ $status = 'configured';
+ try {
+ $version = head($installed)->getVersion();
+ } catch (Exception $ex) {
+ $status = 'error';
+ $exception = $ex;
+ }
+ } else {
+ $status = 'available';
+ $version = null;
+ }
+
+ $linter_info[$key] = array(
+ 'short' => $linter->getLinterConfigurationName(),
+ 'class' => get_class($linter),
+ 'status' => $status,
+ 'version' => $version,
+ 'name' => $linter->getInfoName(),
+ 'uri' => $linter->getInfoURI(),
+ 'description' => $linter->getInfoDescription(),
+ 'exception' => $exception,
+ 'options' => $linter->getLinterConfigurationOptions(),
+ );
+ }
+
+ return isort($linter_info, 'short');
+ }
+
+ private function filterByNames(array $linters, array $search_terms) {
+ $filtered = array();
+
+ foreach ($linters as $key => $linter) {
+ $name = $linter['name'];
+ $short = $linter['short'];
+ $description = $linter['description'];
+ foreach ($search_terms as $term) {
+ if (stripos($name, $term) !== false ||
+ stripos($short, $term) !== false ||
+ stripos($description, $term) !== false) {
+ $filtered[$key] = $linter;
+ }
+ }
+ }
+ return $filtered;
+ }
+
+ private function findExactNames(array $linters, array $names) {
+ $filtered = array();
+
+ foreach ($linters as $key => $linter) {
+ $name = $linter['name'];
+
+ foreach ($names as $term) {
+ if (strcasecmp($name, $term) == 0) {
+ $filtered[$key] = $linter;
+ }
+ }
+ }
+ return $filtered;
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 11:56 PM (19 h, 44 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6922400
Default Alt Text
D10706.diff (8 KB)

Event Timeline