Class: Lemon::CLI::Base
- Inherits:
-
Object
- Object
- Lemon::CLI::Base
- Defined in:
- lib/lemon/cli/base.rb
Overview
Base class for all commands.
Instance Method Summary collapse
-
#initialize(argv = ARGV) ⇒ Base
constructor
A new instance of Base.
- #option_all ⇒ Object
- #option_covered ⇒ Object
-
#option_format ⇒ Object
def option_framework option_parser.on(‘-f’, ‘–framework NAME’, ‘framework syntax to output’) do |name| options = name.to_sym end end.
- #option_loadpath ⇒ Object
- #option_namespaces ⇒ Object
- #option_output ⇒ Object
- #option_parser ⇒ Object
- #option_private ⇒ Object
- #option_requires ⇒ Object
- #option_uncovered ⇒ Object
- #option_verbose ⇒ Object
- #option_zealous ⇒ Object
- #options ⇒ Object
- #run(argv) ⇒ Object
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_all ⇒ Object
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 [:all] = true end end |
#option_covered ⇒ Object
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 [:covered] = true end end |
#option_format ⇒ Object
def option_framework
option_parser.on('-f', '--framework NAME', 'framework syntax to output') do |name|
[: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| [:format] = name end end |
#option_loadpath ⇒ Object
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(/[:;]/) [:loadpath] ||= [] [:loadpath].concat(paths) end end |
#option_namespaces ⇒ Object
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| [:namespaces] ||= [] [:namespaces] << name end end |
#option_output ⇒ Object
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| [:output] = dir end end |
#option_parser ⇒ Object
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_private ⇒ Object
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 [:private] = true end end |
#option_requires ⇒ Object
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(/[:;]/) [:requires] ||= [] [:requires].concat(files) end end |
#option_uncovered ⇒ Object
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 [:uncovered] = true end end |
#option_verbose ⇒ Object
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| [:format] = 'verbose' end end |
#option_zealous ⇒ Object
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 [:zealous] = true end end |
#options ⇒ Object
19 20 21 |
# File 'lib/lemon/cli/base.rb', line 19 def @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 |