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, OBrother, Test

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ Base (private)

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



36
37
38
# File 'lib/lemon/cli/base.rb', line 36

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

Class Method Details

.run(argv) ⇒ Object



11
12
13
# File 'lib/lemon/cli/base.rb', line 11

def self.run(argv)
  new.run(argv)
end

Instance Method Details

#command_parse(argv) ⇒ Object (private)

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



44
45
# File 'lib/lemon/cli/base.rb', line 44

def command_parse(argv)
end

#option_coverageObject (private)

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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_dryrunObject (private)

–dryrun



159
160
161
162
163
# 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_formatObject (private)

-f –format



85
86
87
88
89
# 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_loadpathObject (private)

-I



141
142
143
144
145
146
147
# 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_namespacesObject (private)

-n –namespace



71
72
73
74
75
76
# 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_outputObject (private)

-o –output



134
135
136
137
138
# 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_parserObject (private)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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_privateObject (private)

-p –private



120
121
122
123
124
# 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_requiresObject (private)

-r



150
151
152
153
154
155
156
# 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_verboseObject (private)

-v –verbose



92
93
94
95
96
# 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_zealousObject (private)

-z –zealous



127
128
129
130
131
# 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

#optionsObject



16
17
18
# File 'lib/lemon/cli/base.rb', line 16

def options
  @options
end

#run(argv) ⇒ Object



21
22
23
24
25
26
27
28
29
# 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