rprogram 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +9 -1
- data/LICENSE.txt +1 -1
- data/README.md +6 -10
- data/gemspec.yml +1 -2
- data/lib/rprogram/argument.rb +31 -0
- data/lib/rprogram/non_option.rb +6 -36
- data/lib/rprogram/option.rb +32 -43
- data/lib/rprogram/program.rb +9 -10
- data/lib/rprogram/rprogram.rb +6 -4
- data/lib/rprogram/system.rb +38 -31
- data/lib/rprogram/task.rb +14 -12
- data/lib/rprogram/version.rb +1 -1
- data/rprogram.gemspec +38 -83
- data/spec/classes/aliased_program.rb +2 -0
- data/spec/classes/named_program.rb +2 -0
- data/spec/non_option_spec.rb +10 -12
- data/spec/option_examples.rb +3 -5
- data/spec/option_list_spec.rb +7 -11
- data/spec/option_spec.rb +31 -33
- data/spec/program_spec.rb +8 -7
- data/spec/rprogram_spec.rb +7 -7
- data/spec/system_spec.rb +3 -2
- data/spec/task_spec.rb +43 -36
- metadata +5 -34
- data/lib/rprogram/yard.rb +0 -1
data/lib/rprogram/task.rb
CHANGED
@@ -25,11 +25,11 @@ module RProgram
|
|
25
25
|
# # ...
|
26
26
|
# end
|
27
27
|
#
|
28
|
-
def initialize(options={}
|
28
|
+
def initialize(options={})
|
29
29
|
@subtasks = {}
|
30
|
-
@options
|
30
|
+
@options = options
|
31
31
|
|
32
|
-
|
32
|
+
yield self if block_given?
|
33
33
|
end
|
34
34
|
|
35
35
|
#
|
@@ -293,7 +293,12 @@ module RProgram
|
|
293
293
|
return leading_non_options + options + tailing_args
|
294
294
|
end
|
295
295
|
|
296
|
-
|
296
|
+
#
|
297
|
+
# @see #arguments
|
298
|
+
#
|
299
|
+
def to_a
|
300
|
+
arguments
|
301
|
+
end
|
297
302
|
|
298
303
|
protected
|
299
304
|
|
@@ -487,17 +492,14 @@ module RProgram
|
|
487
492
|
# Task.flag_namify('--output-file')
|
488
493
|
# # => "output_file"
|
489
494
|
#
|
490
|
-
def
|
495
|
+
def self.flag_namify(flag)
|
491
496
|
flag = flag.to_s.downcase
|
492
497
|
|
493
498
|
# remove leading dashes
|
494
|
-
if flag[
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
else
|
499
|
-
method_name = flag
|
500
|
-
end
|
499
|
+
method_name = if flag.start_with?('--') then flag[2..-1]
|
500
|
+
elsif flag.start_with?('-') then flag[1..-1]
|
501
|
+
else flag
|
502
|
+
end
|
501
503
|
|
502
504
|
# replace remaining dashes with underscores
|
503
505
|
return method_name.gsub(/[-_\.\s]+/,'_')
|
data/lib/rprogram/version.rb
CHANGED
data/rprogram.gemspec
CHANGED
@@ -2,104 +2,59 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
lib_dir = File.join(root,'lib')
|
8
|
-
files = `git ls-files`.split($/)
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
when String
|
15
|
-
Dir[paths]
|
16
|
-
end
|
17
|
-
}
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
13
|
+
require 'rprogram/version'
|
14
|
+
RProgram::VERSION
|
15
|
+
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
'doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
31
|
-
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}']
|
32
|
-
}
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
33
23
|
|
34
|
-
|
24
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
35
25
|
|
36
|
-
|
37
|
-
|
38
|
-
metadata['version']
|
39
|
-
else
|
40
|
-
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
26
|
+
gem.files = `git ls-files`.split($/)
|
27
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
41
28
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
47
|
-
gemspec.description = metadata.fetch('description',metadata['summary'])
|
48
|
-
|
49
|
-
gemspec.licenses = Array(metadata['license'])
|
50
|
-
gemspec.authors = Array(metadata['authors'])
|
51
|
-
|
52
|
-
gemspec.email = metadata['email']
|
53
|
-
gemspec.homepage = metadata['homepage']
|
54
|
-
|
55
|
-
gemspec.require_paths = Array(metadata['require_paths'])
|
56
|
-
gemspec.files = filter_files[metadata['files']]
|
57
|
-
gemspec.files += Array(metadata['generated_files'])
|
58
|
-
gemspec.executables = metadata['executables']
|
59
|
-
gemspec.extensions = metadata['extensions']
|
60
|
-
|
61
|
-
if Gem::VERSION < '1.7.'
|
62
|
-
gemspec.default_executable = gemspec.executables.first
|
29
|
+
gem.executables = gemspec.fetch('executables') do
|
30
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
63
31
|
end
|
32
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
64
33
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
gemspec.post_install_message = metadata['post_install_message']
|
69
|
-
gemspec.requirements = metadata['requirements']
|
34
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
35
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
36
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
70
37
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
if gemspec.respond_to?(:required_rubygems_version=)
|
76
|
-
gemspec.required_rubygems_version = metadata['required_ruby_version']
|
77
|
-
end
|
38
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
39
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
40
|
+
})
|
78
41
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
when String
|
84
|
-
versions.split(/,\s*/)
|
85
|
-
end
|
86
|
-
}
|
42
|
+
gem.requirements = gemspec['requirements']
|
43
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
44
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
45
|
+
gem.post_install_message = gemspec['post_install_message']
|
87
46
|
|
88
|
-
|
89
|
-
metadata['dependencies'].each do |name,versions|
|
90
|
-
gemspec.add_dependency(name,parse_versions[versions])
|
91
|
-
end
|
92
|
-
end
|
47
|
+
split = lambda { |string| string.split(/,\s*/) }
|
93
48
|
|
94
|
-
if
|
95
|
-
|
96
|
-
|
49
|
+
if gemspec['dependencies']
|
50
|
+
gemspec['dependencies'].each do |name,versions|
|
51
|
+
gem.add_dependency(name,split[versions])
|
97
52
|
end
|
98
53
|
end
|
99
54
|
|
100
|
-
if
|
101
|
-
|
102
|
-
|
55
|
+
if gemspec['development_dependencies']
|
56
|
+
gemspec['development_dependencies'].each do |name,versions|
|
57
|
+
gem.add_development_dependency(name,split[versions])
|
103
58
|
end
|
104
59
|
end
|
105
60
|
end
|
data/spec/non_option_spec.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'rprogram/non_option'
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
3
|
+
require 'rprogram/non_option'
|
4
|
+
|
5
5
|
describe NonOption do
|
6
|
-
|
7
|
-
@non_option = NonOption.new(:name => 'files')
|
8
|
-
end
|
6
|
+
subject { NonOption.new(:name => 'files') }
|
9
7
|
|
10
8
|
it "should keep :leading and :tailing options mutually exclusive" do
|
11
9
|
leading = NonOption.new(:name => 'files', :leading => true)
|
@@ -19,30 +17,30 @@ describe NonOption do
|
|
19
17
|
end
|
20
18
|
|
21
19
|
it "should return an empty Array when passed nil" do
|
22
|
-
|
20
|
+
subject.arguments(nil).should == []
|
23
21
|
end
|
24
22
|
|
25
23
|
it "should return an empty Array when passed false" do
|
26
|
-
|
24
|
+
subject.arguments(false).should == []
|
27
25
|
end
|
28
26
|
|
29
27
|
it "should return an empty Array when passed []" do
|
30
|
-
|
28
|
+
subject.arguments([]).should == []
|
31
29
|
end
|
32
30
|
|
33
31
|
it "should return an Array when passed a single value" do
|
34
|
-
|
32
|
+
subject.arguments('foo').should == ['foo']
|
35
33
|
end
|
36
34
|
|
37
35
|
it "should return an Array when passed multiple values" do
|
38
|
-
|
36
|
+
subject.arguments(['foo', 'bar']).should == ['foo', 'bar']
|
39
37
|
end
|
40
38
|
|
41
39
|
it "should return an Array when passed a Hash of keys" do
|
42
|
-
|
40
|
+
subject.arguments({:foo => true, :bar => false}).should == ['foo']
|
43
41
|
end
|
44
42
|
|
45
43
|
it "should return an Array when passed a Hash of values" do
|
46
|
-
|
44
|
+
subject.arguments({:foo => 'bar'}).should == ['foo=bar']
|
47
45
|
end
|
48
46
|
end
|
data/spec/option_examples.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
require 'rprogram/option'
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
shared_examples_for 'Option' do
|
6
4
|
it "should return an empty Array when passed nil" do
|
7
|
-
|
5
|
+
subject.arguments(nil).should == []
|
8
6
|
end
|
9
7
|
|
10
8
|
it "should return an empty Array when passed false" do
|
11
|
-
|
9
|
+
subject.arguments(false).should == []
|
12
10
|
end
|
13
11
|
|
14
12
|
it "should return a single flag when passed true" do
|
15
|
-
|
13
|
+
subject.arguments(true).should == ['-f']
|
16
14
|
end
|
17
15
|
end
|
data/spec/option_list_spec.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
-
require 'rprogram/option_list'
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@options = OptionList.new
|
8
|
-
end
|
3
|
+
require 'rprogram/option_list'
|
9
4
|
|
5
|
+
describe OptionList do
|
10
6
|
it "should behave like a Hash" do
|
11
|
-
|
12
|
-
|
7
|
+
subject[:bla] = 2
|
8
|
+
subject[:bla].should == 2
|
13
9
|
end
|
14
10
|
|
15
11
|
it "should provide reader and writer methods" do
|
16
|
-
|
17
|
-
|
12
|
+
subject.bla = 5
|
13
|
+
subject.bla.should == 5
|
18
14
|
end
|
19
15
|
|
20
16
|
it "should raise a NoMethodError exception when calling other methods" do
|
21
17
|
lambda {
|
22
|
-
|
18
|
+
subject.bla(5)
|
23
19
|
}.should raise_error(NoMethodError)
|
24
20
|
end
|
25
21
|
end
|
data/spec/option_spec.rb
CHANGED
@@ -1,52 +1,50 @@
|
|
1
|
-
require 'rprogram/option'
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
require 'option_examples'
|
5
3
|
|
4
|
+
require 'rprogram/option'
|
5
|
+
|
6
6
|
describe Option do
|
7
7
|
describe "custom formatting" do
|
8
8
|
it "should allow the format block to return nil" do
|
9
|
-
opt =
|
9
|
+
opt = described_class.new(:flag => '-f') { |opt,value| }
|
10
10
|
|
11
11
|
opt.arguments('bla').should == []
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "single flag" do
|
16
|
-
|
17
|
-
@option = Option.new(:flag => '-f')
|
18
|
-
end
|
16
|
+
subject { described_class.new(:flag => '-f') }
|
19
17
|
|
20
18
|
it_should_behave_like 'Option'
|
21
19
|
|
22
20
|
it "should render a single flag with an optional value" do
|
23
21
|
value = 'foo'
|
24
22
|
|
25
|
-
|
23
|
+
subject.arguments('foo').should == ['-f', 'foo']
|
26
24
|
end
|
27
25
|
|
28
26
|
it "should render a single flag with multiple values" do
|
29
27
|
value = ['foo','bar','baz']
|
30
28
|
|
31
|
-
|
29
|
+
subject.arguments(value).should == ['-f','foo','bar','baz']
|
32
30
|
end
|
33
31
|
|
34
32
|
it "should render a single flag with a Hash of keys" do
|
35
33
|
value = {:foo => true, :bar => false}
|
36
34
|
|
37
|
-
|
35
|
+
subject.arguments(value).should == ['-f','foo']
|
38
36
|
end
|
39
37
|
|
40
38
|
it "should render a single flag with a Hash of keys and values" do
|
41
39
|
value = {:foo => 'bar'}
|
42
40
|
|
43
|
-
|
41
|
+
subject.arguments(value).should == ['-f','foo=bar']
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
45
|
describe "equals flag" do
|
48
|
-
|
49
|
-
|
46
|
+
subject do
|
47
|
+
described_class.new(:equals => true, :flag => '-f')
|
50
48
|
end
|
51
49
|
|
52
50
|
it_should_behave_like 'Option'
|
@@ -54,25 +52,25 @@ describe Option do
|
|
54
52
|
it "should render a single flag with a value" do
|
55
53
|
value = 'foo'
|
56
54
|
|
57
|
-
|
55
|
+
subject.arguments('foo').should == ['-f=foo']
|
58
56
|
end
|
59
57
|
|
60
58
|
it "should render a single flag with multiple values" do
|
61
59
|
value = ['foo', 'bar', 'baz']
|
62
60
|
|
63
|
-
|
61
|
+
subject.arguments(value).should == ['-f=foo bar baz']
|
64
62
|
end
|
65
63
|
|
66
64
|
it "should render a single flag with a Hash of keys" do
|
67
65
|
value = {:foo => true, :bar => false}
|
68
66
|
|
69
|
-
|
67
|
+
subject.arguments(value).should == ['-f=foo']
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
73
71
|
describe "multiple flags" do
|
74
|
-
|
75
|
-
|
72
|
+
subject do
|
73
|
+
described_class.new(:multiple => true, :flag => '-f')
|
76
74
|
end
|
77
75
|
|
78
76
|
it_should_behave_like 'Option'
|
@@ -80,18 +78,18 @@ describe Option do
|
|
80
78
|
it "should render a single flag with a value" do
|
81
79
|
value = 'foo'
|
82
80
|
|
83
|
-
|
81
|
+
subject.arguments(value).should == ['-f', 'foo']
|
84
82
|
end
|
85
83
|
|
86
84
|
it "should render multiple flags for multiple values" do
|
87
85
|
value = ['foo','bar','baz']
|
88
86
|
|
89
|
-
|
87
|
+
subject.arguments(value).should == ['-f', 'foo', '-f', 'bar', '-f', 'baz']
|
90
88
|
end
|
91
89
|
|
92
90
|
it "should render multiple flags for a Hash of keys" do
|
93
91
|
value = {:foo => true, :bar => true, :baz => false}
|
94
|
-
args =
|
92
|
+
args = subject.arguments(value)
|
95
93
|
|
96
94
|
(args & ['-f', 'foo']).should == ['-f', 'foo']
|
97
95
|
(args & ['-f', 'bar']).should == ['-f', 'bar']
|
@@ -100,13 +98,13 @@ describe Option do
|
|
100
98
|
it "should render multiple flags for a Hash of values" do
|
101
99
|
value = {:foo => 'bar'}
|
102
100
|
|
103
|
-
|
101
|
+
subject.arguments(value).should == ['-f', 'foo=bar']
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
107
105
|
describe "multiple equals flags" do
|
108
|
-
|
109
|
-
|
106
|
+
subject do
|
107
|
+
described_class.new(:multiple => true, :equals => true, :flag => '-f')
|
110
108
|
end
|
111
109
|
|
112
110
|
it_should_behave_like 'Option'
|
@@ -114,18 +112,18 @@ describe Option do
|
|
114
112
|
it "should render a single flag with a value" do
|
115
113
|
value = 'foo'
|
116
114
|
|
117
|
-
|
115
|
+
subject.arguments(value).should == ['-f=foo']
|
118
116
|
end
|
119
117
|
|
120
118
|
it "should render multiple equal flags for multiple values" do
|
121
119
|
value = ['foo', 'bar']
|
122
120
|
|
123
|
-
|
121
|
+
subject.arguments(value).should == ['-f=foo', '-f=bar']
|
124
122
|
end
|
125
123
|
|
126
124
|
it "should render multiple equal flags for a Hash of keys" do
|
127
125
|
value = {:foo => true, :bar => true, :baz => false}
|
128
|
-
args =
|
126
|
+
args = subject.arguments(value)
|
129
127
|
|
130
128
|
args.include?('-f=foo').should == true
|
131
129
|
args.include?('-f=bar').should == true
|
@@ -133,7 +131,7 @@ describe Option do
|
|
133
131
|
|
134
132
|
it "should render multiple equal flags for a Hash of values" do
|
135
133
|
value = {:foo => 'bar', :bar => 'baz'}
|
136
|
-
args =
|
134
|
+
args = subject.arguments(value)
|
137
135
|
|
138
136
|
args.include?('-f=foo=bar').should == true
|
139
137
|
args.include?('-f=bar=baz').should == true
|
@@ -141,8 +139,8 @@ describe Option do
|
|
141
139
|
end
|
142
140
|
|
143
141
|
describe "separated values" do
|
144
|
-
|
145
|
-
|
142
|
+
subject do
|
143
|
+
described_class.new(:separator => ',', :flag => '-f')
|
146
144
|
end
|
147
145
|
|
148
146
|
it_should_behave_like 'Option'
|
@@ -150,18 +148,18 @@ describe Option do
|
|
150
148
|
it "should render a single flag with a value" do
|
151
149
|
value = 'foo'
|
152
150
|
|
153
|
-
|
151
|
+
subject.arguments('foo').should == ['-f', 'foo']
|
154
152
|
end
|
155
153
|
|
156
154
|
it "should render a single flag with multiple values" do
|
157
155
|
value = ['foo', 'bar', 'baz']
|
158
156
|
|
159
|
-
|
157
|
+
subject.arguments(value).should == ['-f', 'foo,bar,baz']
|
160
158
|
end
|
161
159
|
|
162
160
|
it "should render a single flag with a Hash of keys" do
|
163
161
|
value = {:foo => true, :bar => true, :baz => false}
|
164
|
-
args =
|
162
|
+
args = subject.arguments(value)
|
165
163
|
|
166
164
|
args[0].should == '-f'
|
167
165
|
|
@@ -173,7 +171,7 @@ describe Option do
|
|
173
171
|
|
174
172
|
it "should render a single flag with a Hash of values" do
|
175
173
|
value = {:foo => 'bar', :bar => 'baz'}
|
176
|
-
args =
|
174
|
+
args = subject.arguments(value)
|
177
175
|
|
178
176
|
args[0].should == '-f'
|
179
177
|
|