diff --git a/lib/docs.rb b/lib/docs.rb index 95168b55..d12e4570 100644 --- a/lib/docs.rb +++ b/lib/docs.rb @@ -74,6 +74,22 @@ module Docs end end + def self.find_by_slug(slug, version = nil) + doc = all.find { |klass| klass.slug == slug } + + unless doc + raise DocNotFound.new(%(could not find doc with "#{slug}"), slug) + end + + if version.present? + version = doc.versions.find { |klass| klass.version == version || klass.version_slug == version } + raise DocNotFound.new(%(could not find version "#{version}" for doc "#{doc.name}"), doc.name) unless version + doc = version + end + + doc + end + def self.generate_page(name, version, page_id) find(name, version).store_page(store, page_id) end diff --git a/lib/tasks/docs.thor b/lib/tasks/docs.thor index 6b4b211b..a80e19d2 100644 --- a/lib/tasks/docs.thor +++ b/lib/tasks/docs.thor @@ -158,8 +158,14 @@ class DocsCLI < Thor option :packaged, type: :boolean def upload(*names) require 'net/sftp' - names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged] - docs = find_docs(names) + + if options[:packaged] + slugs = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } + docs = find_docs_by_slugs(slugs) + else + docs = find_docs(names) + end + assert_docs(docs) # Sync files with S3 (used by the web app) @@ -251,6 +257,13 @@ class DocsCLI < Thor end end + def find_docs_by_slugs(slugs) + slugs.flat_map do |slug| + slug, version = slug.split(/~/) + Docs.find_by_slug(slug, version) + end + end + def assert_docs(docs) if docs.empty? puts 'ERROR: called with no arguments.'