From d07fc70bbedc60b2554fd838e232dd1d2358eae7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 5 Mar 2014 13:00:50 -0800 Subject: [PATCH] Make `bin/diviner generate` with no arguments mean "generate everything" Summary: Ref T988. This makes it easier to generate documentation. Test Plan: Ran with and without `--book`. Examined CLI output. Reviewers: chad, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T988 Differential Revision: https://secure.phabricator.com/D8415 --- .../workflow/DivinerAtomizeWorkflow.php | 2 +- .../workflow/DivinerGenerateWorkflow.php | 36 ++++++++++++++++++- .../diviner/workflow/DivinerWorkflow.php | 3 +- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/applications/diviner/workflow/DivinerAtomizeWorkflow.php b/src/applications/diviner/workflow/DivinerAtomizeWorkflow.php index 7e00ebfe03..aff3312bb7 100644 --- a/src/applications/diviner/workflow/DivinerAtomizeWorkflow.php +++ b/src/applications/diviner/workflow/DivinerAtomizeWorkflow.php @@ -30,7 +30,7 @@ final class DivinerAtomizeWorkflow extends DivinerWorkflow { } public function execute(PhutilArgumentParser $args) { - $this->readBookConfiguration($args); + $this->readBookConfiguration($args->getArg('book')); $console = PhutilConsole::getConsole(); diff --git a/src/applications/diviner/workflow/DivinerGenerateWorkflow.php b/src/applications/diviner/workflow/DivinerGenerateWorkflow.php index c3511cb785..6975f85c76 100644 --- a/src/applications/diviner/workflow/DivinerGenerateWorkflow.php +++ b/src/applications/diviner/workflow/DivinerGenerateWorkflow.php @@ -38,7 +38,41 @@ final class DivinerGenerateWorkflow extends DivinerWorkflow { } public function execute(PhutilArgumentParser $args) { - $this->readBookConfiguration($args); + $book = $args->getArg('book'); + if ($book) { + $books = array($book); + } else { + $cwd = getcwd(); + $this->log(pht('FINDING DOCUMENTATION BOOKS')); + $books = id(new FileFinder($cwd)) + ->withType('f') + ->withSuffix('book') + ->find(); + + if (!$books) { + throw new PhutilArgumentUsageException( + pht( + "There are no Diviner '.book' files anywhere beneath the ". + "current directory. Use '--book ' to specify a ". + "documentation book to generate.")); + } else { + $this->log(pht('Found %s book(s).', new PhutilNumber(count($books)))); + } + } + + foreach ($books as $book) { + $short_name = basename($book); + + $this->log(pht('Generating book "%s"...', $short_name)); + $this->generateBook($book, $args); + $this->log(pht('Completed generation of "%s".', $short_name)."\n"); + } + } + + private function generateBook($book, PhutilArgumentParser $args) { + $this->atomCache = null; + + $this->readBookConfiguration($book); if ($args->getArg('clean')) { $this->log(pht('CLEARING CACHES')); diff --git a/src/applications/diviner/workflow/DivinerWorkflow.php b/src/applications/diviner/workflow/DivinerWorkflow.php index 43b402aa4a..e0efa46d9a 100644 --- a/src/applications/diviner/workflow/DivinerWorkflow.php +++ b/src/applications/diviner/workflow/DivinerWorkflow.php @@ -17,8 +17,7 @@ abstract class DivinerWorkflow extends PhabricatorManagementWorkflow { return $this->config; } - protected function readBookConfiguration(PhutilArgumentParser $args) { - $book_path = $args->getArg('book'); + protected function readBookConfiguration($book_path) { if ($book_path === null) { throw new PhutilArgumentUsageException( "Specify a Diviner book configuration file with --book.");