class Lemon::CLI::Base

Base class for all commands.

Public Class Methods

new(argv=ARGV) click to toggle source

Initialize new command instance. This will be overriden in subclasses.

# File lib/lemon/cli/base.rb, line 36
def initialize(argv=ARGV)
  @options = {}
end
run(argv) click to toggle source
# File lib/lemon/cli/base.rb, line 11
def self.run(argv)
  new.run(argv)
end

Public Instance Methods

options() click to toggle source
# File lib/lemon/cli/base.rb, line 16
def options
  @options
end
run(argv) click to toggle source
# File lib/lemon/cli/base.rb, line 21
def run(argv)
  begin
    command_parse(argv)
    command_run(argv)
  #rescue => err
  #  raise err if $DEBUG
  #  $stderr.puts('ERROR: ' + err.to_s)
  end
end

Private Instance Methods

command_parse(argv) click to toggle source

Parse command line argument. This is a no-op as it will be overridden in subclasses.

# File lib/lemon/cli/base.rb, line 44
def command_parse(argv)
end
option_coverage() click to toggle source

-c –covered, -u –uncovered and -a –all

# File lib/lemon/cli/base.rb, line 99
def option_coverage
  option_parser.on('-c', '--covered', 'include covered units') do
   if options[:coverage] == :uncovered
      options[:coverage] = :all
   else 
     options[:coverage] = :covered
   end
  end
  option_parser.on('-u', '--uncovered', 'include only uncovered units') do
    if options[:coverage] == :covered
      options[:coverage] = :all
    else
      options[:coverage] = :uncovered
    end
  end
  option_parser.on('-a', '--all', 'include all namespaces and units') do
    options[:coverage] = :all
  end
end
option_dryrun() click to toggle source

–dryrun

# File lib/lemon/cli/base.rb, line 159
def option_dryrun
  option_parser.on('--dryrun', 'no disk writes') do
    options[:dryrun] = true
  end
end
option_format() click to toggle source

-f –format

# File lib/lemon/cli/base.rb, line 85
def option_format
  option_parser.on('-f', '--format NAME', 'output format') do |name|
    options[:format] = name
  end
end
option_loadpath() click to toggle source

-I

# File lib/lemon/cli/base.rb, line 141
def option_loadpath
  option_parser.on("-I PATH" , 'add directory to $LOAD_PATH') do |path|
    paths = path.split(/[:;]/)
    options[:loadpath] ||= []
    options[:loadpath].concat(paths)
  end
end
option_namespaces() click to toggle source

-n –namespace

# File lib/lemon/cli/base.rb, line 71
def option_namespaces
  option_parser.on('-n', '--namespace NAME', 'add a namespace to output') do |name|
    options[:namespaces] ||= []
    options[:namespaces] << name
  end
end
option_output() click to toggle source

-o –output

# File lib/lemon/cli/base.rb, line 134
def option_output
  option_parser.on('-o', '--output DIRECTORY', 'output directory') do |dir|
    options[:output] = dir
  end
end
option_parser() click to toggle source
# File lib/lemon/cli/base.rb, line 48
def option_parser
  @option_parser ||= (
    OptionParser.new do |opt|
      opt.on_tail("--[no-]ansi" , 'turn on/off ANIS colors') do |v|
        $ansi = v
      end
      opt.on_tail("--debug" , 'turn on debugging mode') do
        $DEBUG = true
      end
      opt.on_tail("--about" , 'display information about lemon') do
        puts "Lemon v#{Lemon::VERSION}"
        puts "#{Lemon::COPYRIGHT}"
        exit
      end
      opt.on_tail('-h', '--help', 'display help (also try `<command> --help`)') do
        puts opt
        exit
      end
    end
  )
end
option_private() click to toggle source

-p –private

# File lib/lemon/cli/base.rb, line 120
def option_private
  option_parser.on('-p', '--private', 'include private and protected methods') do
    options[:private] = true
  end
end
option_requires() click to toggle source

-r

# File lib/lemon/cli/base.rb, line 150
def option_requires
 option_parser.on("-r FILE" , 'require file(s) (before doing anything else)') do |files|
    files = files.split(/[:;]/)
    options[:requires] ||= []
    options[:requires].concat(files)
  end
end
option_verbose() click to toggle source

-v –verbose

# File lib/lemon/cli/base.rb, line 92
def option_verbose
  option_parser.on('-v', '--verbose', 'shortcut for `-f verbose`') do |name|
    options[:format] = 'verbose'
  end
end
option_zealous() click to toggle source

-z –zealous

# File lib/lemon/cli/base.rb, line 127
def option_zealous
  option_parser.on('-z', '--zealous', 'include undefined case methods') do
    options[:zealous] = true
  end
end