ame 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +4 -0
- data/Rakefile +9 -0
- data/lib/ame.rb +26 -0
- data/lib/ame/argument.rb +56 -0
- data/lib/ame/arguments.rb +65 -0
- data/lib/ame/class.rb +117 -0
- data/lib/ame/help.rb +5 -0
- data/lib/ame/help/console.rb +96 -0
- data/lib/ame/method.rb +94 -0
- data/lib/ame/methods.rb +30 -0
- data/lib/ame/option.rb +50 -0
- data/lib/ame/options.rb +102 -0
- data/lib/ame/root.rb +57 -0
- data/lib/ame/splat.rb +12 -0
- data/lib/ame/types.rb +29 -0
- data/lib/ame/types/array.rb +16 -0
- data/lib/ame/types/boolean.rb +16 -0
- data/lib/ame/types/integer.rb +11 -0
- data/lib/ame/types/string.rb +9 -0
- data/lib/ame/version.rb +5 -0
- data/test/ame/types/array.rb +13 -0
- data/test/ame/types/boolean.rb +17 -0
- data/test/ame/types/integer.rb +7 -0
- data/test/ame/types/string.rb +6 -0
- data/test/unit/ame/argument.rb +66 -0
- data/test/unit/ame/arguments.rb +106 -0
- data/test/unit/ame/help/console.rb +163 -0
- data/test/unit/ame/method.rb +40 -0
- data/test/unit/ame/methods.rb +10 -0
- data/test/unit/ame/option.rb +75 -0
- data/test/unit/ame/options.rb +136 -0
- data/test/unit/ame/root.rb +15 -0
- data/test/unit/ame/splat.rb +11 -0
- metadata +150 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect Enumerable do Ame::Arguments.new end
|
5
|
+
|
6
|
+
expect 0 do
|
7
|
+
Ame::Arguments.new.arity
|
8
|
+
end
|
9
|
+
expect 1 do
|
10
|
+
Ame::Arguments.new.argument(:a, 'd').arity
|
11
|
+
end
|
12
|
+
expect(-1) do
|
13
|
+
Ame::Arguments.new.argument(:a, 'd', :optional => true).arity
|
14
|
+
end
|
15
|
+
expect 2 do
|
16
|
+
Ame::Arguments.new.argument(:a, 'd').argument(:b, 'd').arity
|
17
|
+
end
|
18
|
+
expect(-2) do
|
19
|
+
Ame::Arguments.new.argument(:a, 'd').
|
20
|
+
argument(:b, 'd', :optional => true).arity
|
21
|
+
end
|
22
|
+
expect(-3) do
|
23
|
+
Ame::Arguments.new.argument(:a, 'd').
|
24
|
+
argument(:b, 'd').
|
25
|
+
argument(:c, 'd', :optional => true).arity
|
26
|
+
end
|
27
|
+
expect(-4) do
|
28
|
+
Ame::Arguments.new.argument(:a, 'd').
|
29
|
+
argument(:b, 'd').
|
30
|
+
splat(:c, 'd').arity
|
31
|
+
end
|
32
|
+
expect(-3) do
|
33
|
+
Ame::Arguments.new.argument(:a, 'd').
|
34
|
+
argument(:b, 'd').
|
35
|
+
splat(:c, 'd', :optional => true).arity
|
36
|
+
end
|
37
|
+
expect(-3) do
|
38
|
+
Ame::Arguments.new.argument(:a, 'd').
|
39
|
+
argument(:b, 'd').
|
40
|
+
argument(:c, 'd', :optional => true).
|
41
|
+
argument(:d, 'd', :optional => true).arity
|
42
|
+
end
|
43
|
+
expect(-3) do
|
44
|
+
Ame::Arguments.new.argument(:a, 'd').splat(:b, 'd').arity
|
45
|
+
end
|
46
|
+
|
47
|
+
expect ArgumentError.new('argument b must come before splat argument a') do
|
48
|
+
Ame::Arguments.new.splat(:a, 'd').argument(:b, 'd')
|
49
|
+
end
|
50
|
+
|
51
|
+
expect ArgumentError.new('optional argument a may not precede required argument b') do
|
52
|
+
Ame::Arguments.new.argument(:a, 'd', :optional => true).argument(:b, 'd')
|
53
|
+
end
|
54
|
+
|
55
|
+
expect ArgumentError.new('splat argument a already defined: b') do
|
56
|
+
Ame::Arguments.new.splat(:a, 'd').splat(:b, 'd')
|
57
|
+
end
|
58
|
+
|
59
|
+
expect ArgumentError.new('optional argument a may not precede required splat argument b') do
|
60
|
+
Ame::Arguments.new.argument(:a, 'd', :optional => true).splat(:b, 'd')
|
61
|
+
end
|
62
|
+
|
63
|
+
expect Ame::MissingArgument do
|
64
|
+
Ame::Arguments.new.argument(:a, 'd').process({}, [])
|
65
|
+
end
|
66
|
+
|
67
|
+
expect [] do
|
68
|
+
Ame::Arguments.new.process({}, [])
|
69
|
+
end
|
70
|
+
|
71
|
+
expect [1] do
|
72
|
+
Ame::Arguments.new.argument(:a, 'd', :type => Integer).process({}, %w[1])
|
73
|
+
end
|
74
|
+
|
75
|
+
expect [1, TrueClass] do
|
76
|
+
Ame::Arguments.new.argument(:a, 'd', :type => Integer).
|
77
|
+
argument(:b, 'd', :type => FalseClass).
|
78
|
+
process({}, %w[1 true])
|
79
|
+
end
|
80
|
+
|
81
|
+
expect Ame::MissingArgument do
|
82
|
+
Ame::Arguments.new.argument(:a, 'd', :type => Integer).
|
83
|
+
splat(:b, 'd').
|
84
|
+
process({}, %w[1])
|
85
|
+
end
|
86
|
+
|
87
|
+
expect [1, []] do
|
88
|
+
Ame::Arguments.new.argument(:a, 'd', :type => Integer).
|
89
|
+
splat(:b, 'd', :optional => true).
|
90
|
+
process({}, %w[1])
|
91
|
+
end
|
92
|
+
|
93
|
+
expect [1, [2, 3]] do
|
94
|
+
Ame::Arguments.new.argument(:a, 'd', :type => Integer).
|
95
|
+
splat(:b, 'd', :type => Integer).
|
96
|
+
process({}, %w[1 2 3])
|
97
|
+
end
|
98
|
+
|
99
|
+
expect Ame::Splat do
|
100
|
+
Ame::Arguments.new.splat(:a, 'd').splat
|
101
|
+
end
|
102
|
+
|
103
|
+
expect Ame::SuperfluousArgument do
|
104
|
+
Ame::Arguments.new.process({}, %w[1])
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect output(%{Usage: help-console-test-1 [OPTIONS]... ARG1 ARG2 ARGN...
|
5
|
+
Method description
|
6
|
+
|
7
|
+
Arguments:
|
8
|
+
ARG1 Argument 1
|
9
|
+
ARG2 Argument 2
|
10
|
+
ARGN... Argument N
|
11
|
+
|
12
|
+
Options:
|
13
|
+
-a, --abc=ABC Abc description
|
14
|
+
--help Display help for this method
|
15
|
+
-v V description
|
16
|
+
--version Display version information
|
17
|
+
-x=LEVEL X description
|
18
|
+
}) do |io|
|
19
|
+
Class.new(Ame::Root) {
|
20
|
+
help Ame::Help::Console.new(io, false)
|
21
|
+
|
22
|
+
description 'Method description'
|
23
|
+
option :abc, 'Abc description', :aliases => :a, :type => String
|
24
|
+
option :v, 'V description'
|
25
|
+
option :x, 'X description', :type => String, :argument => 'level'
|
26
|
+
argument :arg1, 'Argument 1'
|
27
|
+
argument :arg2, 'Argument 2'
|
28
|
+
splat :argN, 'Argument N'
|
29
|
+
def help_console_test_1() end
|
30
|
+
}.process('help-console-test-1', %w[--help])
|
31
|
+
end
|
32
|
+
|
33
|
+
expect output(%{Usage: dispatch [OPTIONS]... METHOD [ARGUMENTS]...
|
34
|
+
Dispatch description
|
35
|
+
|
36
|
+
Arguments:
|
37
|
+
METHOD Method to run
|
38
|
+
[ARGUMENTS]... Arguments to pass to METHOD
|
39
|
+
|
40
|
+
Options:
|
41
|
+
--help Display help for this method
|
42
|
+
--version Display version information
|
43
|
+
|
44
|
+
Methods:
|
45
|
+
method-1 Method 1 does a
|
46
|
+
method-2 Method 2 does b
|
47
|
+
}) do |io|
|
48
|
+
Class.new(Ame::Root) {
|
49
|
+
help Ame::Help::Console.new(io, false)
|
50
|
+
|
51
|
+
dispatch Class.new(Ame::Class) {
|
52
|
+
basename 'dispatch'
|
53
|
+
|
54
|
+
description 'Dispatch description'
|
55
|
+
def initialize() end
|
56
|
+
|
57
|
+
description 'Method 1 does a'
|
58
|
+
def method_1() end
|
59
|
+
|
60
|
+
description 'Method 2 does b'
|
61
|
+
def method_2() end
|
62
|
+
}
|
63
|
+
}.process('dispatch', %w[--help])
|
64
|
+
end
|
65
|
+
|
66
|
+
expect output(%{Usage: dispatch-1 dispatch-2 [OPTIONS]... METHOD [ARGUMENTS]...
|
67
|
+
Dispatch 2 description
|
68
|
+
|
69
|
+
Arguments:
|
70
|
+
METHOD Method to run
|
71
|
+
[ARGUMENTS]... Arguments to pass to METHOD
|
72
|
+
|
73
|
+
Options:
|
74
|
+
--help Display help for this method
|
75
|
+
|
76
|
+
Methods:
|
77
|
+
method-1 Method 1 does a
|
78
|
+
method-2 Method 2 does b
|
79
|
+
}) do |io|
|
80
|
+
Class.new(Ame::Root) {
|
81
|
+
help Ame::Help::Console.new(io, false)
|
82
|
+
|
83
|
+
dispatch Class.new(Ame::Class) {
|
84
|
+
basename 'dispatch-1'
|
85
|
+
|
86
|
+
description 'Dispatch 1 description'
|
87
|
+
def initialize() end
|
88
|
+
|
89
|
+
dispatch Class.new(Ame::Class) {
|
90
|
+
basename 'dispatch-2'
|
91
|
+
|
92
|
+
description 'Dispatch 2 description'
|
93
|
+
def initialize() end
|
94
|
+
|
95
|
+
description 'Method 1 does a'
|
96
|
+
def method_1() end
|
97
|
+
|
98
|
+
description 'Method 2 does b'
|
99
|
+
def method_2() end
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}.process('dispatch-1', %w[dispatch-2 --help])
|
103
|
+
end
|
104
|
+
|
105
|
+
expect output(%{Usage: dispatch [OPTIONS]... [METHOD] [ARGUMENTS]...
|
106
|
+
Dispatch description
|
107
|
+
|
108
|
+
Arguments:
|
109
|
+
[METHOD=method-1] Method to run
|
110
|
+
[ARGUMENTS]... Arguments to pass to METHOD
|
111
|
+
|
112
|
+
Options:
|
113
|
+
--help Display help for this method
|
114
|
+
--version Display version information
|
115
|
+
|
116
|
+
Methods:
|
117
|
+
method-1 Method 1 does a
|
118
|
+
method-2 Method 2 does b
|
119
|
+
}) do |io|
|
120
|
+
Class.new(Ame::Root) {
|
121
|
+
help Ame::Help::Console.new(io, false)
|
122
|
+
|
123
|
+
dispatch Class.new(Ame::Class) {
|
124
|
+
basename 'dispatch'
|
125
|
+
|
126
|
+
description 'Dispatch description'
|
127
|
+
def initialize() end
|
128
|
+
|
129
|
+
description 'Method 1 does a'
|
130
|
+
def method_1() end
|
131
|
+
|
132
|
+
description 'Method 2 does b'
|
133
|
+
def method_2() end
|
134
|
+
}, :default => 'method-1'
|
135
|
+
}.process('dispatch', %w[--help])
|
136
|
+
end
|
137
|
+
|
138
|
+
expect output(%{method 0.1.0\n}) do |io|
|
139
|
+
Class.new(Ame::Root) {
|
140
|
+
Version = '0.1.0'
|
141
|
+
|
142
|
+
help Ame::Help::Console.new(io)
|
143
|
+
|
144
|
+
description 'd'
|
145
|
+
def method() end
|
146
|
+
}.process 'method', %w[--version]
|
147
|
+
end
|
148
|
+
|
149
|
+
expect output("method: error message\n") do |io|
|
150
|
+
begin
|
151
|
+
Class.new(Ame::Root) {
|
152
|
+
help Ame::Help::Console.new(io, false)
|
153
|
+
|
154
|
+
description 'd'
|
155
|
+
def method()
|
156
|
+
raise 'error message'
|
157
|
+
end
|
158
|
+
}.process 'method', []
|
159
|
+
rescue RuntimeError => e
|
160
|
+
raise unless e.message == 'error message'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect 'd' do Ame::Method.new(nil).description('d').description end
|
5
|
+
|
6
|
+
expect Ame::Method.new(nil).not.to.be.valid?
|
7
|
+
|
8
|
+
expect Ame::Method.new(nil).description('d').to.be.valid?
|
9
|
+
|
10
|
+
expect :name do Ame::Method.new(nil).description('d').define(:name).name end
|
11
|
+
|
12
|
+
expect mock.to.receive.method('b', 1, true, ['d', 'e', 'f'], {:a => true}).once do |o|
|
13
|
+
Ame::Method.new(o).
|
14
|
+
option(:a, 'd').
|
15
|
+
argument(:a, 'd').
|
16
|
+
argument(:b, 'd', :type => Integer).
|
17
|
+
argument(:c, 'd', :type => FalseClass).
|
18
|
+
splat(:d, 'd').
|
19
|
+
description('d').
|
20
|
+
define(:method).
|
21
|
+
process o, %w[b -a 1 on d e f]
|
22
|
+
end
|
23
|
+
|
24
|
+
expect mock.to.receive.method(1, false, [], {:a => 5}).once do |o|
|
25
|
+
Ame::Method.new(o).
|
26
|
+
option(:a, 'd', :default => 5).
|
27
|
+
argument(:b, 'd', :optional => true, :default => 1).
|
28
|
+
argument(:c, 'd', :optional => true, :default => false).
|
29
|
+
splat(:d, 'd', :optional => true).
|
30
|
+
description('d').
|
31
|
+
define(:method).
|
32
|
+
call o
|
33
|
+
end
|
34
|
+
|
35
|
+
expect Ame::Class.to.receive.help_for_method(Ame::Method) do |o|
|
36
|
+
catch Ame::AbortAllProcessing do
|
37
|
+
Ame::Method.new(o).description('d').define(:method).process o, %w[--help]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect Enumerable do Ame::Methods.new end
|
5
|
+
|
6
|
+
expect Ame::Methods.new do |o| o << Ame::Method.new(nil) end
|
7
|
+
|
8
|
+
expect Ame::Method.new(nil) do |o| (Ame::Methods.new << o.define(:name))[:name] end
|
9
|
+
expect Ame::Method.new(nil) do |o| (Ame::Methods.new << o.define(:name))['name'] end
|
10
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect Ame::Argument do
|
5
|
+
Ame::Option.new(:a, 'd')
|
6
|
+
end
|
7
|
+
|
8
|
+
expect ArgumentError do
|
9
|
+
Ame::Option.new(:a, 'd', :type => String, :optional => true)
|
10
|
+
end
|
11
|
+
|
12
|
+
expect Ame::Option.new(:a, 'd').to.be.optional?
|
13
|
+
|
14
|
+
expect Ame::Option.new(:a, 'd', :type => String).not.to.be.optional?
|
15
|
+
|
16
|
+
expect FalseClass do
|
17
|
+
Ame::Option.new(:a, 'd').default
|
18
|
+
end
|
19
|
+
|
20
|
+
expect TrueClass do
|
21
|
+
Ame::Option.new(:a, 'd').process({}, [], 'true')
|
22
|
+
end
|
23
|
+
|
24
|
+
expect FalseClass do
|
25
|
+
Ame::Option.new(:a, 'd').process({}, [], 'off')
|
26
|
+
end
|
27
|
+
|
28
|
+
expect 'string' do
|
29
|
+
Ame::Option.new(:a, 'd', :type => String).process({}, [], 'string')
|
30
|
+
end
|
31
|
+
|
32
|
+
expect 'a' do
|
33
|
+
Ame::Option.new(:a, 'd', :type => String).argument_name
|
34
|
+
end
|
35
|
+
|
36
|
+
expect 'b' do
|
37
|
+
Ame::Option.new(:a, 'd', :argument => 'b', :type => String).argument_name
|
38
|
+
end
|
39
|
+
|
40
|
+
expect ArgumentError do
|
41
|
+
Ame::Option.new(:a, 'd', :argument => 'a').argument_name
|
42
|
+
end
|
43
|
+
|
44
|
+
expect [:b] do
|
45
|
+
Ame::Option.new(:a, 'd', :aliases => :b).aliases
|
46
|
+
end
|
47
|
+
|
48
|
+
expect [:b, :c, :d] do
|
49
|
+
Ame::Option.new(:a, 'd', :aliases => [:b, :c, :d]).aliases
|
50
|
+
end
|
51
|
+
|
52
|
+
expect [:b, :c, :d] do
|
53
|
+
Ame::Option.new(:a, 'd', :alias => :b, :aliases => [:c, :d]).aliases
|
54
|
+
end
|
55
|
+
|
56
|
+
expect '-a' do
|
57
|
+
Ame::Option.new(:a, 'd').to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
expect '--abc' do
|
61
|
+
Ame::Option.new(:abc, 'd').to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
expect :a do
|
65
|
+
Ame::Option.new(:abc, 'd', :aliases => [:a, :b]).short
|
66
|
+
end
|
67
|
+
|
68
|
+
expect :abc do
|
69
|
+
Ame::Option.new(:a, 'd', :aliases => [:abc, :b]).long
|
70
|
+
end
|
71
|
+
|
72
|
+
expect Ame::Option.new(:a, 'd').not.to.be.ignored?
|
73
|
+
|
74
|
+
expect Ame::Option.new(:a, 'd', :ignore => true).to.be.ignored?
|
75
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect Enumerable do
|
5
|
+
Ame::Options.new
|
6
|
+
end
|
7
|
+
|
8
|
+
expect [:a, :b] do
|
9
|
+
Ame::Options.new.option('a', 'd').option('b', 'd').map{ |o| o.name }
|
10
|
+
end
|
11
|
+
|
12
|
+
expect [:a, :b] do
|
13
|
+
Ame::Options.new.option(:a, 'd').option(:b, 'd').map{ |o| o.name }
|
14
|
+
end
|
15
|
+
|
16
|
+
expect ArgumentError do
|
17
|
+
Ame::Options.new.option(:a, 'd').option(:a, 'd')
|
18
|
+
end
|
19
|
+
|
20
|
+
expect Ame::Options.new.option(:a, 'd').to.include?('a')
|
21
|
+
expect Ame::Options.new.option(:a, 'd').to.include?(:a)
|
22
|
+
|
23
|
+
expect [{:a => 1, :b => 2}, []] do
|
24
|
+
Ame::Options.new.
|
25
|
+
option(:a, 'd', :default => 1).
|
26
|
+
option(:b, 'd', :default => 2).process([])
|
27
|
+
end
|
28
|
+
|
29
|
+
expect [{:a => 3, :b => 4}, []] do
|
30
|
+
Ame::Options.new.
|
31
|
+
option(:a, 'd', :default => 1).
|
32
|
+
option(:b, 'd', :default => 2).process(['-a=3', '-b=4'])
|
33
|
+
end
|
34
|
+
|
35
|
+
expect [{:a => 3, :b => 4}, []] do
|
36
|
+
Ame::Options.new.
|
37
|
+
option(:a, 'd', :default => 1).
|
38
|
+
option(:b, 'd', :default => 2).process(['-a', '3', '-b', '4'])
|
39
|
+
end
|
40
|
+
|
41
|
+
expect Ame::MalformedArgument do
|
42
|
+
Ame::Options.new.option(:a, 'd', :default => 1).process(['-a='])
|
43
|
+
end
|
44
|
+
|
45
|
+
expect Ame::MissingArgument do
|
46
|
+
Ame::Options.new.option(:a, 'd', :default => 1).process(['-a'])
|
47
|
+
end
|
48
|
+
|
49
|
+
expect Ame::UnrecognizedOption do
|
50
|
+
Ame::Options.new.option(:a, 'd', :default => 1).process(['-b'])
|
51
|
+
end
|
52
|
+
|
53
|
+
expect Ame::MalformedArgument do
|
54
|
+
Ame::Options.new.
|
55
|
+
option(:a, 'd', :default => 1).
|
56
|
+
option(:b, 'd').process(['-ab'])
|
57
|
+
end
|
58
|
+
|
59
|
+
expect Ame::MissingArgument do
|
60
|
+
Ame::Options.new.
|
61
|
+
option(:a, 'd').
|
62
|
+
option(:b, 'd', :default => 1).process(['-ab'])
|
63
|
+
end
|
64
|
+
|
65
|
+
expect [{:a => true, :b => 2}, []] do
|
66
|
+
Ame::Options.new.
|
67
|
+
option(:a, 'd').
|
68
|
+
option(:b, 'd', :default => 1).process(['-ab2'])
|
69
|
+
end
|
70
|
+
|
71
|
+
expect [{:a => true, :b => 2}, []] do
|
72
|
+
Ame::Options.new.
|
73
|
+
option(:a, 'd').
|
74
|
+
option(:b, 'd', :default => 1).process(['-ab', '2'])
|
75
|
+
end
|
76
|
+
|
77
|
+
expect [{:a => true, :b => true}, []] do
|
78
|
+
Ame::Options.new.
|
79
|
+
option(:a, 'd').
|
80
|
+
option(:b, 'd').process(['-ab'])
|
81
|
+
end
|
82
|
+
|
83
|
+
expect [{:a => true, :b => true}, []] do
|
84
|
+
Ame::Options.new.
|
85
|
+
option(:a, 'd').
|
86
|
+
option(:b, 'd').process(['-a', '-b'])
|
87
|
+
end
|
88
|
+
|
89
|
+
expect [{:a => true, :b => false}, ['-b']] do
|
90
|
+
Ame::Options.new.
|
91
|
+
option(:a, 'd').
|
92
|
+
option(:b, 'd').process(['-a', '--', '-b'])
|
93
|
+
end
|
94
|
+
|
95
|
+
expect [{:a => true, :b => true}, ['arg']] do
|
96
|
+
stub(ENV).include?{ false }
|
97
|
+
Ame::Options.new.
|
98
|
+
option(:a, 'd').
|
99
|
+
option(:b, 'd').process(['arg', '-a', '-b'])
|
100
|
+
end
|
101
|
+
|
102
|
+
expect [{:a => false, :b => false}, ['arg', '-a', '-b']] do
|
103
|
+
Ame::Options.new.
|
104
|
+
options_must_precede_arguments.
|
105
|
+
option(:a, 'd').
|
106
|
+
option(:b, 'd').process(['arg', '-a', '-b'])
|
107
|
+
end
|
108
|
+
|
109
|
+
expect [{:a => true}, []] do
|
110
|
+
Ame::Options.new.option(:a, 'd', :aliases => [:b]).process(['-b'])
|
111
|
+
end
|
112
|
+
|
113
|
+
expect [{:a => false}, []] do
|
114
|
+
Ame::Options.new.option(:a, 'd', :default => true).process(['-a'])
|
115
|
+
end
|
116
|
+
|
117
|
+
expect [{:abc => true}, []] do
|
118
|
+
Ame::Options.new.option(:abc, 'd').process(['--abc'])
|
119
|
+
end
|
120
|
+
|
121
|
+
expect [{:abc => 1}, []] do
|
122
|
+
Ame::Options.new.option(:abc, 'd', :type => Integer).process(['--abc=1'])
|
123
|
+
end
|
124
|
+
|
125
|
+
expect [{:abc => 1}, []] do
|
126
|
+
Ame::Options.new.option(:abc, 'd', :type => Integer).process(['--abc', '1'])
|
127
|
+
end
|
128
|
+
|
129
|
+
expect [{}, []] do
|
130
|
+
Ame::Options.new.option(:abc, 'd', :ignore => true).process(['--abc'])
|
131
|
+
end
|
132
|
+
|
133
|
+
expect [{:a => [1, 2, 3]}, []] do
|
134
|
+
Ame::Options.new.option(:a, 'd', :type => Ame::Types::Array[Integer]).process(%w[-a 1 -a 2 -a 3])
|
135
|
+
end
|
136
|
+
end
|