lib/yard/cli/yri.rb in yard-0.5.5 vs lib/yard/cli/yri.rb in yard-0.5.6
- old
+ new
@@ -1,5 +1,7 @@
+require 'rbconfig'
+
module YARD
module CLI
# A tool to view documentation in the console like `ri`
class YRI < Base
CACHE_FILE = File.expand_path('~/.yard/yri_cache')
@@ -25,22 +27,34 @@
# YRI.new.run('String#reverse')
# @param [Array<String>] args each tokenized argument
def run(*args)
optparse(*args)
- @serializer ||= YARD::Serializers::ProcessSerializer.new('less')
+ if Config::CONFIG['host_os'] =~ /mingw|win32/
+ @serializer ||= YARD::Serializers::StdoutSerializer.new
+ else
+ @serializer ||= YARD::Serializers::ProcessSerializer.new('less')
+ end
- if object = find_object(@name)
+ if @name.nil? || @name.strip.empty?
+ print_usage
+ exit(1)
+ elsif object = find_object(@name)
print_object(object)
else
STDERR.puts "No documentation for `#{@name}'"
exit(1)
end
end
protected
+ def print_usage
+ puts "Usage: yri [options] <Path to object>"
+ puts "See yri --help for more options."
+ end
+
def cache_object(name, path)
return if path == Registry.yardoc_file
@cache[name] = path
File.open!(CACHE_FILE, 'w') do |file|
@@ -110,10 +124,11 @@
# Parses commandline options.
# @param [Array<String>] args each tokenized argument
def optparse(*args)
opts = OptionParser.new
-
+ opts.banner = "Usage: yri [options] <Path to object>"
+ opts.separator "Example: yri String#gsub"
opts.separator ""
opts.separator "General Options:"
opts.on('-b', '--db FILE', 'Use a specified .yardoc db to search in') do |yfile|
@search_paths.unshift(yfile)
\ No newline at end of file