Skip to content

Commit c0b0ead

Browse files
committed
Better CLI parsing, and use -V for verbose.
1 parent c7fa655 commit c0b0ead

1 file changed

Lines changed: 34 additions & 23 deletions

File tree

lib/rubytest/cli.rb

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,34 @@ module Test
22

33
# Command line interface to test runner.
44
#
5-
# TODO: Use `cli` based library instead of option parse.
5+
# TODO: Use `cli` based library instead of option parser?
66
#
77
class CLI
88

9-
#
109
# Convenience method for invoking the CLI.
1110
#
11+
# @return nothing
1212
def self.run(*argv)
1313
new.run(*argv)
1414
end
1515

16-
#
1716
# Initialize CLI instance.
1817
#
18+
# @return nothing
1919
def initialize
2020
require 'optparse'
2121
end
2222

23+
# Test run configuration.
2324
#
25+
# @return [Config]
2426
def config
2527
@config ||= Test.configuration
2628
end
2729

28-
#
2930
# Run tests.
3031
#
32+
# @return nothing
3133
def run(argv=nil)
3234
begin
3335
require 'dotopts'
@@ -53,17 +55,9 @@ def run(argv=nil)
5355
end
5456
end
5557

56-
# These options are parsed prior to any other options.
57-
#
58-
# TODO: Certain opitons should be parsed before others.
59-
# Some aren't even useful if not, use as -R.
60-
def preoptions
61-
62-
end
63-
64-
#
6558
# Setup OptionsParser instance.
6659
#
60+
# @return [OptionParser]
6761
def options
6862
this = self
6963

@@ -90,36 +84,38 @@ def options
9084
end
9185

9286
opt.on '-t', '--tag TAG', 'select tests by tag' do |tag|
93-
config.tags << tag
87+
config.tags.concat enlist(tag)
9488
end
9589
opt.on '-u', '--unit TAG', 'select tests by software unit' do |unit|
96-
config.units << unit
90+
config.units.concat enlist(unit)
9791
end
9892
opt.on '-m', '--match TEXT', 'select tests by description' do |text|
99-
config.match << text
93+
config.match.concat enlist(text)
10094
end
10195

10296
opt.on '-A', '--autopath', 'automatically add paths to $LOAD_PATH' do |paths|
10397
config.autopath = true
10498
end
10599
opt.on '-I', '--loadpath PATH', 'add given path to $LOAD_PATH' do |paths|
106-
paths.split(/[:;]/).reverse_each do |path|
107-
$LOAD_PATH.unshift path
108-
end
100+
#enlist(paths).reverse_each do |path|
101+
# $LOAD_PATH.unshift path
102+
#end
103+
config.loadpath.concat enlist(paths)
109104
end
110105
#opt.on '-C', '--chdir DIR', 'change directory before running tests' do |dir|
111106
# config.chdir = dir
112107
#end
113108
#opt.on '-R', '--chroot', 'change to project root directory before running tests' do |bool|
114109
# config.chroot = bool
115110
#end
116-
opt.on '-r', '--require FILE', 'require file (immediately)' do |file|
117-
require file
111+
opt.on '-r', '--require FILE', 'require file' do |file|
112+
#require file
113+
config.requires.concat pathlist(file)
118114
end
119-
opt.on '-c', '--config FILE', "require local config file" do |file|
115+
opt.on '-c', '--config FILE', "require local config file (immediately)" do |file|
120116
Config.require_config(file)
121117
end
122-
opt.on '-d' , '--details', 'provide extra detail in reports' do
118+
opt.on '-V' , '--verbose', 'provide extra detail in reports' do
123119
config.verbose = true
124120
end
125121
#opt.on('--log DIRECTORY', 'log directory'){ |dir|
@@ -141,6 +137,21 @@ def options
141137
end
142138
end
143139

140+
# If given a String then split up at `:` and `;` markers.
141+
# Otherwise ensure the list is an Array and the entries are
142+
# all strings and not empty.
143+
#
144+
# @return [Array<String>]
145+
def enlist(list)
146+
case list
147+
when String
148+
list = list.split(/[:;]/)
149+
else
150+
list = Array(list).map{ |path| path.to_s }
151+
end
152+
list.reject{ |path| path.strip.empty? }
153+
end
154+
144155
end
145156

146157
end

0 commit comments

Comments
 (0)