<?php

final class PhabricatorStorageManagementStatusWorkflow
  extends PhabricatorStorageManagementWorkflow {

  public function didConstruct() {
    $this
      ->setName('status')
      ->setExamples('**status** [__options__]')
      ->setSynopsis('Show patch application status.');
  }

  public function execute(PhutilArgumentParser $args) {
    $api = $this->getAPI();
    $patches = $this->getPatches();

    $applied = $api->getAppliedPatches();

    if ($applied === null) {
      echo phutil_console_format(
        "**Database Not Initialized**: Run **storage upgrade** to ".
        "initialize.\n");

      return 1;
    }

    $len = 0;
    foreach ($patches as $patch) {
      $len = max($len, strlen($patch->getFullKey()));
    }

    foreach ($patches as $patch) {
      printf(

        "% -".($len + 2)."s ".
        "%-".strlen('Not Applied')."s   ".
        "%-4s   ".
        "%s\n",

        $patch->getFullKey(),
        in_array($patch->getFullKey(), $applied)
          ? 'Applied'
          : 'Not Applied',
        $patch->getType(),
        $patch->getName());
    }

    return 0;
  }

}

<?php

final class PhabricatorStorageManagementStatusWorkflow
  extends PhabricatorStorageManagementWorkflow {

  public function didConstruct() {
    $this
      ->setName('status')
      ->setExamples('**status** [__options__]')
      ->setSynopsis('Show patch application status.');
  }

  public function execute(PhutilArgumentParser $args) {
    $api = $this->getAPI();
    $patches = $this->getPatches();

    $applied = $api->getAppliedPatches();

    if ($applied === null) {
      echo phutil_console_format(
        "**Database Not Initialized**: Run **storage upgrade** to ".
        "initialize.\n");

      return 1;
    }

    $table = id(new PhutilConsoleTable())
      ->setShowHeader(false)
      ->addColumn('id',     array('title' => 'ID'))
      ->addColumn('status', array('title' => 'Status'))
      ->addColumn('type',   array('title' => 'Type'))
      ->addColumn('name',   array('title' => 'Name'));

    foreach ($patches as $patch) {
      $table->addRow(array(
        'id' => $patch->getFullKey(),
        'status' => in_array($patch->getFullKey(), $applied)
          ? 'Applied'
          : 'Not Applied',
        'type' => $patch->getType(),
        'name' => $patch->getName(),
      ));
    }

    $table->draw();
    return 0;
  }

}

Convert `./bin/storage status` to use `PhutilConsoleTable`.
Convert `./bin/storage status` to use `PhutilConsoleTable`.

Summary: Constructing tables manually just isn't fun.

Test Plan:
```
./bin/storage status
phabricator:db.audit                                      Applied db   audit
phabricator:db.calendar                                   Applied db   calendar
phabricator:db.chatlog                                    Applied db   chatlog
phabricator:db.conduit                                    Applied db   conduit
phabricator:db.countdown                                  Applied db   countdown
phabricator:db.daemon                                     Applied db   daemon
phabricator:db.differential                               Applied db   differential
phabricator:db.draft                                      Applied db   draft
phabricator:db.drydock                                    Applied db   drydock
phabricator:db.feed                                       Applied db   feed
phabricator:db.file                                       Applied db   file
phabricator:db.flag                                       Applied db   flag
phabricator:db.harbormaster                               Applied db   harbormaster
...
```

This probably isn't ready to land yet, we should fix `PhutilConsoleTable` to truncate columns which would otherwise cause overflow.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9604
