Improve 'docs:download' command

- Add --default option
- Add --installed option
- De-document --all option. With multi-version support just added, the
  complete set of documentations is quickly going to grow beyond its
  current size of 500MB and 30,000 documents.

Ref #25.
pull/308/merge
Thibaut Courouble 9 years ago
parent 4f3ea92bea
commit d5c54c6f52

@ -27,15 +27,15 @@ DevDocs requires Ruby 2.3.0, libcurl, and a JavaScript runtime supported by [Exe
git clone https://github.com/Thibaut/devdocs.git && cd devdocs
gem install bundler
bundle install
thor docs:download --all
thor docs:download --default
rackup
```
Finally, point your browser at [localhost:9292](http://localhost:9292) (the first request will take a few seconds to compile the assets). You're all set.
The `thor docs:download` command is used to download/update individual documentations (e.g. `thor docs:download html css`), or all at the same time (using the `--all` option). You can see the list of available documentations by running `thor docs:list`.
The `thor docs:download` command is used to download pre-generated documentations from DevDocs's servers (e.g. `thor docs:download html css`). You can see the list of available documentations and versions by running `thor docs:list`. To update all downloaded documentations, run `thor docs:download --installed`.
**Note:** there is currently no update mechanism other than `git pull origin master` to update the code and `thor docs:download` to download the latest version of the docs. To stay informed about new releases, be sure to [watch](https://github.com/Thibaut/devdocs/subscription) this repository and/or subscribe to the [newsletter](http://eepurl.com/HnLUz).
**Note:** there is currently no update mechanism other than `git pull origin master` to update the code and `thor docs:download --installed` to download the latest version of the docs. To stay informed about new releases, be sure to [watch](https://github.com/Thibaut/devdocs/subscription) this repository.
Alternatively, DevDocs may be started as a Docker container:

@ -10,8 +10,9 @@ app.templates.intro = """
<li>Your local version of DevDocs won't self-update. Unless you're modifying the code,
I&nbsp;recommend using the hosted version at <a href="http://devdocs.io">devdocs.io</a>.
<li>Run <code>thor docs:list</code> to see all available documentations.
<li>Run <code>thor docs:download --all</code> to download/update all documentations.
<li>To be notified about new versions, don't forget to <a href="https://github.com/Thibaut/devdocs/subscription">watch the repository</a> on GitHub.
<li>Run <code>thor docs:download &lt;name&gt;</code> to download documentations.
<li>Run <code>thor docs:download --installed</code> to update all downloaded documentations.
<li>To be notified about new versions, don't forget to <a href="https://github.com/Thibaut/devdocs/subscription">watch the repository</a> on GitHub.
<li>The <a href="https://github.com/Thibaut/devdocs/issues">issue tracker</a> is the preferred channel for bug reports and
feature requests. For everything else, use the <a href="https://groups.google.com/d/forum/devdocs">mailing list</a>.
<li>Contributions are welcome. See the <a href="https://github.com/Thibaut/devdocs/blob/master/CONTRIBUTING.md">guidelines</a>.

@ -39,7 +39,19 @@ module Docs
all.flat_map(&:versions)
end
def self.find(name, version)
def self.defaults
%w(css dom dom_events html http javascript).map(&method(:find))
end
def self.installed
Dir["#{store_path}/**/index.json"].
map { |file| file[%r{/([^/]*)/index\.json\z}, 1] }.
sort!.
map { |path| all_versions.find { |doc| doc.path == path } }.
compact
end
def self.find(name, version = nil)
const = name.camelize
doc = const_get(const)

@ -94,11 +94,21 @@ class DocsCLI < Thor
puts 'Done'
end
desc 'download (<doc> <doc@version>... | --all)', 'Download documentations'
desc 'download (<doc> <doc@version>... | --default | --installed)', 'Download documentations'
option :default, type: :boolean
option :installed, type: :boolean
option :all, type: :boolean
def download(*names)
require 'unix_utils'
docs = options[:all] ? Docs.all : find_docs(names)
docs = if options[:default]
Docs.defaults
elsif options[:installed]
Docs.installed
elsif options[:all]
Docs.all_versions
else
find_docs(names)
end
assert_docs(docs)
download_docs(docs)
generate_manifest
@ -136,7 +146,7 @@ class DocsCLI < Thor
def assert_docs(docs)
if docs.empty?
puts 'ERROR: called with no arguments.'
puts 'Run "thor docs:list" for usage patterns.'
puts 'Run "thor list" for usage patterns.'
exit
end
end
@ -154,6 +164,7 @@ class DocsCLI < Thor
require 'thread'
length = docs.length
mutex = Mutex.new
i = 0
(1..4).map do
@ -165,7 +176,7 @@ class DocsCLI < Thor
rescue => e
"FAILED (#{e.class}: #{e.message})"
end
puts "(#{i += 1}/#{length}) #{doc.name} #{status}"
mutex.synchronize { puts "(#{i += 1}/#{length}) #{doc.name}#{ " #{doc.version}" if doc.version} #{status}" }
end
end
end.map(&:join)

Loading…
Cancel
Save