class Octaccord::Command::Completions
Public Class Methods
new(help, global_options, arguments)
click to toggle source
# File lib/octaccord/command/completions.rb, line 5 def initialize(help, global_options, arguments) command_name = arguments.first if command_name and help[command_name] options(help, global_options, command_name) else commands(help) end end
Private Instance Methods
commands(help)
click to toggle source
# File lib/octaccord/command/completions.rb, line 17 def commands(help) puts "_values" puts "Sub-commands:" puts "help[Available commands or one specific COMMAND]" help.each do |name, option| next if name == "completions" puts "#{name}[#{option.description}]" end end
options(help, global_options, command_name)
click to toggle source
# File lib/octaccord/command/completions.rb, line 28 def options(help, global_options, command_name) print "_arguments\n-A\n*\n" options = help[command_name].options.merge(global_options) options.each do |name, opt| if opt.type == :boolean print "(--#{name})--#{name}[#{opt.description}]\n" else print "(--#{name})--#{name}=-[#{opt.description}]:#{opt.banner}:#{possible_values(opt)}\n" end end end
possible_values(option)
click to toggle source
# File lib/octaccord/command/completions.rb, line 41 def possible_values(option) return "(" + option.enum.join(" ") + ")" if option.enum case option.banner when "FILE" "_files" when "DIRECTORY" "_files -/" else "" end end