Skip to content

Commit 3b39fa7

Browse files
committed
Fix "thor docs:upload --packaged" not finding docs whose slug is different than name
1 parent 817dac1 commit 3b39fa7

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/docs.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ def self.find(name, version = nil)
7474
end
7575
end
7676

77+
def self.find_by_slug(slug, version = nil)
78+
doc = all.find { |klass| klass.slug == slug }
79+
80+
unless doc
81+
raise DocNotFound.new(%(could not find doc with "#{slug}"), slug)
82+
end
83+
84+
if version.present?
85+
version = doc.versions.find { |klass| klass.version == version || klass.version_slug == version }
86+
raise DocNotFound.new(%(could not find version "#{version}" for doc "#{doc.name}"), doc.name) unless version
87+
doc = version
88+
end
89+
90+
doc
91+
end
92+
7793
def self.generate_page(name, version, page_id)
7894
find(name, version).store_page(store, page_id)
7995
end

lib/tasks/docs.thor

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,14 @@ class DocsCLI < Thor
158158
option :packaged, type: :boolean
159159
def upload(*names)
160160
require 'net/sftp'
161-
names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]
162-
docs = find_docs(names)
161+
162+
if options[:packaged]
163+
slugs = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') }
164+
docs = find_docs_by_slugs(slugs)
165+
else
166+
docs = find_docs(names)
167+
end
168+
163169
assert_docs(docs)
164170

165171
# Sync files with S3 (used by the web app)
@@ -251,6 +257,13 @@ class DocsCLI < Thor
251257
end
252258
end
253259

260+
def find_docs_by_slugs(slugs)
261+
slugs.flat_map do |slug|
262+
slug, version = slug.split(/~/)
263+
Docs.find_by_slug(slug, version)
264+
end
265+
end
266+
254267
def assert_docs(docs)
255268
if docs.empty?
256269
puts 'ERROR: called with no arguments.'

0 commit comments

Comments
 (0)