This is the toplevel "main" command.
New Usage.
# File lib/clio/usage/command.rb, line 15 def initialize(name=nil, &block) name ||= File.basename($0) super(name, &block) end
Cache usage into a per-user cache file for reuse. This can be used to greatly speed up tab completion.
# File lib/clio/usage/command.rb, line 138 def cache File.open(cache_file, 'w'){ |f| f << to_yaml } end
#alias_method :[], :command # ARRAY NOTATION #------------------------------------------------------------- # def [](*args) res = nil head, *tail = *args case head.to_s when /^-/ x = [] opts = args.map do |o| o = o.to_s if i = o.index('=') x << o[i+1..-1] o[0...i] else o end end x = x.uniq res = opt(*opts) else args.each do |name| res = command(name) end end return res end # Usage text. # def to_s #s = [full_name] s = [name] case options.size when 0 when 1, 2, 3 s.concat(options.collect{ |o| "[#{o.to_s.strip}]" }) else s << "[switches]" end
# switches? vs. options
s << arguments.join(' ') unless arguments.empty? case commands.size when 0 when 1 s << commands.join('') when 2, 3 s << '[' + commands.join(' | ') + ']' else s << 'command' end s.flatten.join(' ') end # Help text. # def to_s_help s = [] unless help.empty? s << help s << '' end s << "Usage:" s << " " + to_s unless commands.empty? s << '' s << 'Commands:' s.concat(commands.collect{ |x| " %-20s %s" % [x.key, x.help] }.sort) end unless arguments.empty? s << '' s << "Arguments:" s.concat(arguments.collect{ |x| " %-20s %s" % [x, x.help] }) end unless options.empty? s << '' s << 'Switches:' s.concat(options.collect{ |x| " %-20s %s" % [x, x.help] }) end s.flatten.join("\n") end
# File lib/clio/usage/command.rb, line 131 def parse(argv) Parser.new(self, argv).parse #(argv) end
Generated with the Darkfish Rdoc Generator 2.