Class: Lemon::CLI::Base
- Inherits:
-
Object
- Object
- Lemon::CLI::Base
- Defined in:
- lib/lemon/cli/base.rb
Overview
Base class for all commands.
Class Method Summary collapse
Instance Method Summary collapse
-
#command_parse(argv) ⇒ Object
private
Parse command line argument.
-
#initialize(argv = ARGV) ⇒ Base
constructor
private
Initialize new command instance.
-
#option_coverage ⇒ Object
private
-c –covered, -u –uncovered and -a –all.
-
#option_dryrun ⇒ Object
private
–dryrun.
-
#option_format ⇒ Object
private
-f –format.
-
#option_loadpath ⇒ Object
private
-I.
-
#option_namespaces ⇒ Object
private
-n –namespace.
-
#option_output ⇒ Object
private
-o –output.
- #option_parser ⇒ Object private
-
#option_private ⇒ Object
private
-p –private.
-
#option_requires ⇒ Object
private
-r.
-
#option_verbose ⇒ Object
private
-v –verbose.
-
#option_zealous ⇒ Object
private
-z –zealous.
- #options ⇒ Object
- #run(argv) ⇒ Object
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_coverage ⇒ Object (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 [:coverage] == :uncovered [:coverage] = :all else [:coverage] = :covered end end option_parser.on('-u', '--uncovered', 'include only uncovered units') do if [:coverage] == :covered [:coverage] = :all else [:coverage] = :uncovered end end option_parser.on('-a', '--all', 'include all namespaces and units') do [:coverage] = :all end end |
#option_dryrun ⇒ Object (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 [:dryrun] = true end end |
#option_format ⇒ Object (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| [:format] = name end end |
#option_loadpath ⇒ Object (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(/[:;]/) [:loadpath] ||= [] [:loadpath].concat(paths) end end |
#option_namespaces ⇒ Object (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| [:namespaces] ||= [] [:namespaces] << name end end |
#option_output ⇒ Object (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| [:output] = dir end end |
#option_parser ⇒ Object (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_private ⇒ Object (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 [:private] = true end end |
#option_requires ⇒ Object (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(/[:;]/) [:requires] ||= [] [:requires].concat(files) end end |
#option_verbose ⇒ Object (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| [:format] = 'verbose' end end |
#option_zealous ⇒ Object (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 [:zealous] = true end end |
#options ⇒ Object
16 17 18 |
# File 'lib/lemon/cli/base.rb', line 16 def @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 |