mothership 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mothership.rb +1 -1
- data/lib/mothership/inputs.rb +8 -6
- data/lib/mothership/version.rb +1 -1
- data/spec/flags_spec.rb +28 -28
- data/spec/spec_helper.rb +31 -0
- metadata +6 -4
data/lib/mothership.rb
CHANGED
@@ -28,7 +28,7 @@ class Mothership
|
|
28
28
|
name, *argv = global_parser.parse_flags(argv, @@commands)
|
29
29
|
|
30
30
|
global = new
|
31
|
-
global.input = Inputs.new(@@global, global, global_parser
|
31
|
+
global.input = Inputs.new(@@global, global, global_parser)
|
32
32
|
|
33
33
|
return global.default_action unless name
|
34
34
|
|
data/lib/mothership/inputs.rb
CHANGED
@@ -66,7 +66,7 @@ class Mothership
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
val = get(name, @context, *args)
|
69
|
+
found, val = get(name, @context, *args)
|
70
70
|
|
71
71
|
@inputs[name] = val unless meta && meta[:forget]
|
72
72
|
|
@@ -99,16 +99,18 @@ class Mothership
|
|
99
99
|
|
100
100
|
if @command && meta = @command.inputs[name]
|
101
101
|
found, val = find_in(@given, name, meta, context, *args)
|
102
|
-
elsif
|
103
|
-
found, val =
|
102
|
+
elsif @global.is_a?(self.class)
|
103
|
+
found, val = @global.get(name, context, *args)
|
104
|
+
elsif @global.key?(name)
|
105
|
+
return [true, @global[name]]
|
104
106
|
end
|
105
107
|
|
106
|
-
return val if not found
|
108
|
+
return [false, val] if not found
|
107
109
|
|
108
110
|
if val == :interact && interact = meta[:interact]
|
109
|
-
context.instance_exec(*args, &interact)
|
111
|
+
[true, context.instance_exec(*args, &interact)]
|
110
112
|
else
|
111
|
-
convert_given(meta, context, val, *args)
|
113
|
+
[true, convert_given(meta, context, val, *args)]
|
112
114
|
end
|
113
115
|
ensure
|
114
116
|
@current_input = before_input
|
data/lib/mothership/version.rb
CHANGED
data/spec/flags_spec.rb
CHANGED
@@ -5,33 +5,33 @@ describe Mothership::Parser do
|
|
5
5
|
describe "any" do
|
6
6
|
it "accepts --foo=bar and --foo bar" do
|
7
7
|
command(:foo => {}) do |c|
|
8
|
-
inputs(c, "--foo=bar").should == {:foo => "bar"}
|
9
|
-
inputs(c, "--foo", "bar").should == {:foo => "bar"}
|
8
|
+
inputs(c, "--foo=bar").should == { :foo => "bar" }
|
9
|
+
inputs(c, "--foo", "bar").should == { :foo => "bar" }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it "accepts --foo-bar bar as :foo_bar => \"bar\"" do
|
14
14
|
command(:foo_bar => {}) do |c|
|
15
|
-
inputs(c, "--foo-bar", "bar").should == {:foo_bar => "bar"}
|
15
|
+
inputs(c, "--foo-bar", "bar").should == { :foo_bar => "bar" }
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
it "accepts --foo as :foo => \"\"" do
|
20
20
|
command(:foo => {}) do |c|
|
21
|
-
inputs(c, "--foo").should == {:foo => ""}
|
21
|
+
inputs(c, "--foo").should == { :foo => "" }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe :integer do
|
27
27
|
it "interprets --foo 1 as :foo => 1" do
|
28
|
-
command(:foo => {:type => :integer}) do |c|
|
29
|
-
inputs(c, "--foo", "1").should == {:foo => 1}
|
28
|
+
command(:foo => { :type => :integer }) do |c|
|
29
|
+
inputs(c, "--foo", "1").should == { :foo => 1 }
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
it "fails with --foo bar" do
|
34
|
-
command(:foo => {:type => :integer}) do |c|
|
34
|
+
command(:foo => { :type => :integer }) do |c|
|
35
35
|
proc {
|
36
36
|
inputs(c, "--foo", "bar")
|
37
37
|
}.should raise_error(Mothership::TypeMismatch)
|
@@ -39,7 +39,7 @@ describe Mothership::Parser do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "fails with --foo" do
|
42
|
-
command(:foo => {:type => :integer}) do |c|
|
42
|
+
command(:foo => { :type => :integer }) do |c|
|
43
43
|
proc {
|
44
44
|
inputs(c, "--foo")
|
45
45
|
}.should raise_error(Mothership::TypeMismatch)
|
@@ -49,25 +49,25 @@ describe Mothership::Parser do
|
|
49
49
|
|
50
50
|
describe :float do
|
51
51
|
it "interprets --foo 1 as :foo => 1.0" do
|
52
|
-
command(:foo => {:type => :float}) do |c|
|
53
|
-
inputs(c, "--foo", "1").should == {:foo => 1.0}
|
52
|
+
command(:foo => { :type => :float }) do |c|
|
53
|
+
inputs(c, "--foo", "1").should == { :foo => 1.0 }
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
it "interprets --foo 1. as :foo => 1.0" do
|
58
|
-
command(:foo => {:type => :float}) do |c|
|
59
|
-
inputs(c, "--foo", "1.").should == {:foo => 1.0}
|
58
|
+
command(:foo => { :type => :float }) do |c|
|
59
|
+
inputs(c, "--foo", "1.").should == { :foo => 1.0 }
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
it "interprets --foo 2.5 as :foo => 2.5" do
|
64
|
-
command(:foo => {:type => :float}) do |c|
|
65
|
-
inputs(c, "--foo", "2.5").should == {:foo => 2.5}
|
64
|
+
command(:foo => { :type => :float }) do |c|
|
65
|
+
inputs(c, "--foo", "2.5").should == { :foo => 2.5 }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
it "fails with --foo bar" do
|
70
|
-
command(:foo => {:type => :float}) do |c|
|
70
|
+
command(:foo => { :type => :float }) do |c|
|
71
71
|
proc {
|
72
72
|
inputs(c, "--foo", "bar")
|
73
73
|
}.should raise_error(Mothership::TypeMismatch)
|
@@ -75,7 +75,7 @@ describe Mothership::Parser do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "fails with --foo" do
|
78
|
-
command(:foo => {:type => :float}) do |c|
|
78
|
+
command(:foo => { :type => :float }) do |c|
|
79
79
|
proc {
|
80
80
|
inputs(c, "--foo")
|
81
81
|
}.should raise_error(Mothership::TypeMismatch)
|
@@ -85,36 +85,36 @@ describe Mothership::Parser do
|
|
85
85
|
|
86
86
|
describe :boolean do
|
87
87
|
it "interprets --foo as :foo => true" do
|
88
|
-
command(:foo => {:type => :boolean}) do |c|
|
89
|
-
inputs(c, "--foo").should == {:foo => true}
|
88
|
+
command(:foo => { :type => :boolean }) do |c|
|
89
|
+
inputs(c, "--foo").should == { :foo => true }
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
it "interprets --no-foo as :foo => false" do
|
94
|
-
command(:foo => {:type => :boolean}) do |c|
|
95
|
-
inputs(c, "--no-foo").should == {:foo => false}
|
94
|
+
command(:foo => { :type => :boolean }) do |c|
|
95
|
+
inputs(c, "--no-foo").should == { :foo => false }
|
96
96
|
end
|
97
97
|
end
|
98
98
|
it "interprets --foo true as :foo => true" do
|
99
|
-
command(:foo => {:type => :boolean}) do |c|
|
100
|
-
inputs(c, "--foo", "true").should == {:foo => true}
|
99
|
+
command(:foo => { :type => :boolean }) do |c|
|
100
|
+
inputs(c, "--foo", "true").should == { :foo => true }
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
it "interprets --no-foo true as :foo => false" do
|
105
|
-
command(:foo => {:type => :boolean}) do |c|
|
106
|
-
inputs(c, "--no-foo", "true").should == {:foo => false}
|
105
|
+
command(:foo => { :type => :boolean }) do |c|
|
106
|
+
inputs(c, "--no-foo", "true").should == { :foo => false }
|
107
107
|
end
|
108
108
|
end
|
109
109
|
it "interprets --foo false as :foo => false" do
|
110
|
-
command(:foo => {:type => :boolean}) do |c|
|
111
|
-
inputs(c, "--foo", "false").should == {:foo => false}
|
110
|
+
command(:foo => { :type => :boolean }) do |c|
|
111
|
+
inputs(c, "--foo", "false").should == { :foo => false }
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
it "interprets --no-foo false as :foo => true" do
|
116
|
-
command(:foo => {:type => :boolean}) do |c|
|
117
|
-
inputs(c, "--no-foo", "false").should == {:foo => true}
|
116
|
+
command(:foo => { :type => :boolean }) do |c|
|
117
|
+
inputs(c, "--no-foo", "false").should == { :foo => true }
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "mothership"
|
2
|
+
|
3
|
+
module MothershipHelpers
|
4
|
+
def command(inputs = {})
|
5
|
+
cmd = Mothership::Command.new(Mothership)
|
6
|
+
|
7
|
+
inputs.each do |name, opts|
|
8
|
+
cmd.add_input(name, opts)
|
9
|
+
end
|
10
|
+
|
11
|
+
if block_given?
|
12
|
+
yield cmd
|
13
|
+
else
|
14
|
+
cmd
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def inputs(cmd, *argv)
|
19
|
+
input_hash = {}
|
20
|
+
given = Mothership::Parser.new(cmd).parse_argv(argv)
|
21
|
+
inputs = Mothership::Inputs.new(cmd, nil, {}, given)
|
22
|
+
given.each_key do |k|
|
23
|
+
input_hash[k] = inputs[k]
|
24
|
+
end
|
25
|
+
input_hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RSpec.configure do |c|
|
30
|
+
c.include MothershipHelpers
|
31
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mothership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Suraci
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-12-
|
18
|
+
date: 2012-12-05 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- spec/combination_spec.rb
|
74
74
|
- spec/flags_spec.rb
|
75
75
|
- spec/Rakefile
|
76
|
+
- spec/spec_helper.rb
|
76
77
|
homepage: https://github.com/vito/mothership
|
77
78
|
licenses: []
|
78
79
|
|
@@ -111,3 +112,4 @@ test_files:
|
|
111
112
|
- spec/combination_spec.rb
|
112
113
|
- spec/flags_spec.rb
|
113
114
|
- spec/Rakefile
|
115
|
+
- spec/spec_helper.rb
|