public function run()

in src/workflow/ArcanistLintersWorkflow.php [46:197]


  public function run() {
    $console = PhutilConsole::getConsole();

    $linters = id(new PhutilClassMapQuery())
      ->setAncestorClass('ArcanistLinter')
      ->execute();

    try {
      $built = $this->newLintEngine()->buildLinters();
    } catch (ArcanistNoEngineException $ex) {
      $built = array();
    }

    $linter_info = $this->getLintersInfo($linters, $built);

    $status_map = $this->getStatusMap();
    $pad = '    ';

    $color_map = array(
      'configured' => 'green',
      'available' => 'yellow',
      '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];
      $text = $status_map[$status];
      $print_tail = false;

      $console->writeOut(
        "<bg:".$color.">** %s **</bg> **%s** (%s)\n",
        $text,
        nonempty($linter['name'], '-'),
        $linter['short']);

      if ($linter['exception']) {
        $console->writeOut(
          "\n%s**%s**\n%s\n",
          $pad,
          get_class($linter['exception']),
          phutil_console_wrap(
            $linter['exception']->getMessage(),
            strlen($pad)));
        $print_tail = true;
      }

      if ($is_verbose) {
        $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']);
        }

        $description = $linter['description'];
        if ($description) {
          $console->writeOut(
            "\n%s\n",
            phutil_console_wrap($linter['description'], strlen($pad)));
          $print_tail = true;
        }

        $options = $linter['options'];
        if ($options) {
          $console->writeOut(
            "\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;
        }

        $additional = $linter['additional'];
        foreach ($additional as $title => $body) {
          $console->writeOut(
            "\n%s**%s**\n\n",
            $pad,
            $title);

          // TODO: This should maybe use `tsprintf`.
          // See some discussion in D14563.
          echo $body;
        }

        if ($print_tail) {
          $console->writeOut("\n");
        }
      }
    }

    if (!$is_verbose) {
      $console->writeOut(
        "%s\n",
        pht('(Run `%s` for more details.)', 'arc linters --verbose'));
    }
  }