Exception: Console::Command::UnknownOptionError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/qualitysmith_extensions/console/command.rb

Overview

# We include a module here so you can define your own help

# command and call #super to utilize this one.

module Help

  def help
    opts = help_options
    s = ""
    s << "#{File.basename($0)}\n\n"
    unless opts.empty?
      s << "OPTIONS\n"
      s << help_options
      s << "\n"
    end
    s << "COMMANDS\n"
    s << help_commands
    puts s
  end

  private

  def help_commands
    help = self.class.help
    bufs = help.keys.collect{ |a| a.to_s.size }.max + 3
    lines = []
    help.each { |cmd, str|
      cmd = cmd.to_s
      if cmd !~ /^_/
        lines << "  " + cmd + (" " * (bufs - cmd.size)) + str
      end
    }
    lines.join("\n")
  end

  def help_options
    help = self.class.help
    bufs = help.keys.collect{ |a| a.to_s.size }.max + 3
    lines = []
    help.each { |cmd, str|
      cmd = cmd.to_s
      if cmd =~ /^_/
        lines << "  " + cmd.gsub(/_/,'-') + (" " * (bufs - cmd.size)) + str
      end
    }
    lines.join("\n")
  end

  module ClassMethods

    def help( str=nil )
      return (@help ||= {}) unless str
      @current_help = str
    end

    def method_added( meth )
      if @current_help
        @help ||= {}
        @help[meth] = @current_help
        @current_help = nil
      end
    end

  end

end

include Help
extend Help::ClassMethods

Instance Method Summary collapse

Constructor Details

#initialize(option_name) ⇒ UnknownOptionError

Returns a new instance of UnknownOptionError.



595
596
597
# File 'lib/qualitysmith_extensions/console/command.rb', line 595

def initialize(option_name)
  @option_name = option_name
end

Instance Method Details

#messageObject



598
599
600
# File 'lib/qualitysmith_extensions/console/command.rb', line 598

def message
  "Unknown option '#{@option_name}'."
end