class RainforestCli::Commands
Constants
- Command
- SUPPORTED_COMMANDS
Attributes
commands[R]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/rainforest_cli/commands.rb, line 11 def initialize @commands = [] yield(self) if block_given? end
Public Instance Methods
add(command, description, &blk)
click to toggle source
# File lib/rainforest_cli/commands.rb, line 16 def add(command, description, &blk) @commands << Command.new(command, description, blk) end
call(command_name)
click to toggle source
# File lib/rainforest_cli/commands.rb, line 20 def call(command_name) command = @commands.find { |c| c.name == command_name } if command.nil? logger.fatal "Unknown command: #{command_name}" exit 2 end command.block.call end
print_documentation()
click to toggle source
# File lib/rainforest_cli/commands.rb, line 31 def print_documentation command_col_width = @commands.map { |c| c.name.length }.max puts 'Usage: Rainforest CLI commands:' @commands.each do |command| puts "\t#{command.name.ljust(command_col_width)}\t\t#{command.description}" end end
Private Instance Methods
logger()
click to toggle source
# File lib/rainforest_cli/commands.rb, line 41 def logger RainforestCli.logger end