class Noir::Command::Completion
Public Class Methods
execute(*args)
click to toggle source
# File lib/noir/command/completion.rb, line 7 def execute *args puts suggestions(args) end
suggestions(list)
click to toggle source
# File lib/noir/command/completion.rb, line 11 def suggestions list if list.size.zero? return suggestions_from_command Noir::Command, nil end commands = [:Noir, :Command] + list matched_commands = [commands.first] commands = commands.drop(1) while true consts = eval(matched_commands.map(&:to_s).join('::')).constants(true) break if commands.size.zero? matched_command = consts.find{|c| c.to_s.downcase == commands.first.to_s.downcase} break if matched_command.nil? matched_commands << matched_command commands = commands.drop(1) end command_class = eval(matched_commands.map(&:to_s).join('::')) suggestions_from_command(command_class, commands.first) end
suggestions_from_command(klass, pattern = nil)
click to toggle source
# File lib/noir/command/completion.rb, line 36 def suggestions_from_command klass, pattern = nil suggests = klass.sub_commands.map(&:to_s).map(&:downcase) unless pattern.nil? suggests = suggests.select{|c| c.start_with? pattern.downcase} end return suggests end