Class: Lemon::CLI::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lemon/cli/base.rb

Overview

Base class for all commands.

Direct Known Subclasses

Coverage, Generate, Test

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ Base

Returns a new instance of Base.



14
15
16
# File 'lib/lemon/cli/base.rb', line 14

def initialize(argv=ARGV)
  @options = {}
end

Instance Method Details

#option_allObject



95
96
97
98
99
# File 'lib/lemon/cli/base.rb', line 95

def option_all
  option_parser.on('-a', '--all', 'include all namespaces and units') do
    options[:all] = true
  end
end

#option_coveredObject



83
84
85
86
87
# File 'lib/lemon/cli/base.rb', line 83

def option_covered
  option_parser.on('-c', '--covered', 'include covered units') do
    options[:covered] = true
  end
end

#option_formatObject

def option_framework

option_parser.on('-f', '--framework NAME', 'framework syntax to output') do |name|
  options[:framework] = name.to_sym
end

end



71
72
73
74
75
# File 'lib/lemon/cli/base.rb', line 71

def option_format
  option_parser.on('-f', '--format NAME', 'output format') do |name|
    options[:format] = name
  end
end

#option_loadpathObject



119
120
121
122
123
124
125
# File 'lib/lemon/cli/base.rb', line 119

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_namespacesObject



58
59
60
61
62
63
# File 'lib/lemon/cli/base.rb', line 58

def option_namespaces
  option_parser.on('-n', '--namespace NAME', 'add a namespace to output') do |name|
    options[:namespaces] ||= []
    options[:namespaces] << name
  end
end

#option_outputObject



113
114
115
116
117
# File 'lib/lemon/cli/base.rb', line 113

def option_output
  option_parser.on('-o', '--output DIRECTORY', 'log directory') do |dir|
    options[:output] = dir
  end
end

#option_parserObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/lemon/cli/base.rb', line 35

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_privateObject



101
102
103
104
105
# File 'lib/lemon/cli/base.rb', line 101

def option_private
  option_parser.on('-p', '--private', 'include private and protected methods') do
    options[:private] = true
  end
end

#option_requiresObject



127
128
129
130
131
132
133
# File 'lib/lemon/cli/base.rb', line 127

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_uncoveredObject



89
90
91
92
93
# File 'lib/lemon/cli/base.rb', line 89

def option_uncovered
  option_parser.on('-u', '--uncovered', 'include only uncovered units') do
    options[:uncovered] = true
  end
end

#option_verboseObject



77
78
79
80
81
# File 'lib/lemon/cli/base.rb', line 77

def option_verbose
  option_parser.on('-v', '--verbose', 'shortcut for `-f verbose`') do |name|
    options[:format] = 'verbose'
  end
end

#option_zealousObject



107
108
109
110
111
# File 'lib/lemon/cli/base.rb', line 107

def option_zealous
  option_parser.on('-z', '--zealous', 'include undefined case methods') do
    options[:zealous] = true
  end
end

#optionsObject



19
20
21
# File 'lib/lemon/cli/base.rb', line 19

def options
  @options
end

#run(argv) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/lemon/cli/base.rb', line 24

def run(argv)
  begin
    command_parse(argv)
    command_run(argv)
  rescue => err
    raise err if $DEBUG
    $stderr.puts('ERROR: ' + err.to_s)
  end
end