From caa2592e4bf30ced3cc283d56f61c2050814157f Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 6 Mar 2016 16:15:57 -0500 Subject: [PATCH] Add --all option to docs:generate command For generating all versions of a doc. --- lib/docs.rb | 5 +++-- lib/tasks/docs.thor | 30 +++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/docs.rb b/lib/docs.rb index c3354ba5..33d54bbc 100644 --- a/lib/docs.rb +++ b/lib/docs.rb @@ -75,8 +75,9 @@ module Docs find(name, version).store_page(store, page_id) end - def self.generate(name, version) - find(name, version).store_pages(store) + def self.generate(doc, version = nil) + doc = find(doc, version) unless doc.respond_to?(:store_pages) + doc.store_pages(store) end def self.generate_manifest diff --git a/lib/tasks/docs.thor b/lib/tasks/docs.thor index 46118bed..f8c7af20 100644 --- a/lib/tasks/docs.thor +++ b/lib/tasks/docs.thor @@ -52,6 +52,7 @@ class DocsCLI < Thor desc 'generate [--version] [--verbose] [--debug] [--force] [--package]', 'Generate a documentation' option :version, type: :string + option :all, type: :boolean option :verbose, type: :boolean option :debug, type: :boolean option :force, type: :boolean @@ -74,16 +75,20 @@ class DocsCLI < Thor return unless yes? 'Proceed? (y/n)' end - if Docs.generate(name, options[:version]) - generate_manifest - if options[:package] - require 'unix_utils' - package_doc(Docs.find(name, options[:version])) + require 'unix_utils' if options[:package] + + doc = Docs.find(name, options[:version]) + + result = if doc.version && options[:all] + doc.superclass.versions.all? do |_doc| + puts "==> #{_doc.version}" + generate_doc(_doc, package: options[:package]).tap { puts "\n" } end - puts 'Done' else - puts "Failed!#{' (try running with --debug for more information)' unless options[:debug]}" + generate_doc(doc, package: options[:package]) end + + generate_manifest if result rescue Docs::DocNotFound => error handle_doc_not_found_error(error) end @@ -169,6 +174,17 @@ class DocsCLI < Thor puts 'Run "thor docs:list" to see the list of docs and versions.' end + def generate_doc(doc, package: nil) + if Docs.generate(doc) + package_doc(doc) if package + puts 'Done' + true + else + puts "Failed!#{' (try running with --debug for more information)' unless options[:debug]}" + false + end + end + def download_docs(docs) # Don't allow downloaded files to be created as StringIO require 'open-uri'