Class: Uncool::CLI
- Inherits:
-
Object
- Object
- Uncool::CLI
- Defined in:
- lib/uncool/cli.rb
Overview
CLI Interface handle all lemon sub-commands.
Constant Summary collapse
- COMMANDS =
['coverage', 'generate']
Class Method Summary collapse
Instance Method Summary collapse
- #coverage(scripts) ⇒ Object
- #coverage_parse(argv) ⇒ Object
- #generate(scripts) ⇒ Object
- #generate_parse(argv) ⇒ Object
-
#initialize(argv = ARGV) ⇒ CLI
constructor
A new instance of CLI.
- #option_format ⇒ Object
- #option_framework ⇒ Object
- #option_generate ⇒ Object
- #option_loadpath ⇒ Object
-
#option_namespaces ⇒ Object
P A R S E R O P T I O N S.
- #option_output ⇒ Object
- #option_parser ⇒ Object
-
#option_private ⇒ Object
TODO: How feasible is it to parse tests of various frameworks to check “writ” coverage? def option_uncovered option_parser.on(‘-u’, ‘–uncovered’, ‘include only uncovered tests’) do options = true end end.
- #option_requires ⇒ Object
- #options ⇒ Object
- #run(argv) ⇒ Object
Constructor Details
#initialize(argv = ARGV) ⇒ CLI
Returns a new instance of CLI.
16 17 18 |
# File 'lib/uncool/cli.rb', line 16 def initialize(argv=ARGV) @options = {} end |
Class Method Details
.run(argv = ARGV) ⇒ Object
11 12 13 |
# File 'lib/uncool/cli.rb', line 11 def self.run(argv=ARGV) new.run(argv) end |
Instance Method Details
#coverage(scripts) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/uncool/cli.rb', line 40 def coverage(scripts) require 'uncool/app' app = App.new() app.log scripts.each do |file| require(file) end end |
#coverage_parse(argv) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/uncool/cli.rb', line 53 def coverage_parse(argv) option_namespaces option_private option_output option_format #option_uncovered option_loadpath option_requires option_parser.parse!(argv) end |
#generate(scripts) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/uncool/cli.rb', line 68 def generate(scripts) require 'uncool/app' app = App.new() output = app.generate(scripts) $stdout.puts(output) end |
#generate_parse(argv) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/uncool/cli.rb', line 79 def generate_parse(argv) option_generate option_namespaces option_framework option_private option_loadpath option_requires option_parser.parse!(argv) end |
#option_format ⇒ Object
124 125 126 127 128 |
# File 'lib/uncool/cli.rb', line 124 def option_format option_parser.on('--format', '-f NAME', 'output format') do |name| [:format] = name end end |
#option_framework ⇒ Object
99 100 101 102 103 |
# File 'lib/uncool/cli.rb', line 99 def option_framework option_parser.on('-f', '--framework NAME', 'framework syntax to output') do |name| [:framework] = name.to_sym end end |
#option_generate ⇒ Object
146 147 148 149 |
# File 'lib/uncool/cli.rb', line 146 def option_generate option_parser.on('-g' , '--generate', 'code generation mode') do end end |
#option_loadpath ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/uncool/cli.rb', line 130 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
P A R S E R O P T I O N S
92 93 94 95 96 97 |
# File 'lib/uncool/cli.rb', line 92 def option_namespaces option_parser.on('-n', '--namespace NAME', 'add a namespace to output') do |name| [:namespaces] ||= [] [:namespaces] << name end end |
#option_output ⇒ Object
118 119 120 121 122 |
# File 'lib/uncool/cli.rb', line 118 def option_output option_parser.on('-o', '--output DIRECTORY', 'log directory') do |dir| [:output] = dir end end |
#option_parser ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/uncool/cli.rb', line 151 def option_parser @option_parser ||= ( OptionParser.new do |opt| opt.on_tail("--debug" , 'turn on debugging mode') do $DEBUG = true end opt.on_tail('-h', '--help', 'display this help messae') do puts opt exit 0 end end ) end |
#option_private ⇒ Object
TODO: How feasible is it to parse tests of various frameworks to check “writ” coverage? def option_uncovered
option_parser.on('-u', '--uncovered', 'include only uncovered tests') do
[:uncovered] = true
end
end
112 113 114 115 116 |
# File 'lib/uncool/cli.rb', line 112 def option_private option_parser.on('-p', '--private', 'include private and protected methods') do [:private] = true end end |
#option_requires ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/uncool/cli.rb', line 138 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 |
#options ⇒ Object
21 22 23 |
# File 'lib/uncool/cli.rb', line 21 def @options end |
#run(argv) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/uncool/cli.rb', line 26 def run(argv) if argv.include?('-g') or argv.include?('--generate') cmd = 'generate' else cmd = 'coverage' end cmd = COMMANDS.find{ |c| /^#{cmd}/ =~ c } __send__("#{cmd}_parse", argv) __send__("#{cmd}", argv) end |