Fix "thor docs:upload --packaged" not finding docs whose slug is different than name

pull/944/head
Thibaut Courouble 6 years ago
parent 817dac1c48
commit 3b39fa747f

@ -74,6 +74,22 @@ module Docs
end end
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) def self.generate_page(name, version, page_id)
find(name, version).store_page(store, page_id) find(name, version).store_page(store, page_id)
end end

@ -158,8 +158,14 @@ class DocsCLI < Thor
option :packaged, type: :boolean option :packaged, type: :boolean
def upload(*names) def upload(*names)
require 'net/sftp' require 'net/sftp'
names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]
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) docs = find_docs(names)
end
assert_docs(docs) assert_docs(docs)
# Sync files with S3 (used by the web app) # Sync files with S3 (used by the web app)
@ -251,6 +257,13 @@ class DocsCLI < Thor
end end
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) def assert_docs(docs)
if docs.empty? if docs.empty?
puts 'ERROR: called with no arguments.' puts 'ERROR: called with no arguments.'

Loading…
Cancel
Save