ame 0.1.1 → 1.0.1

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.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/README +541 -3
  3. data/Rakefile +15 -6
  4. data/lib/ame-1.0.rb +31 -0
  5. data/lib/ame-1.0/argument.rb +63 -0
  6. data/lib/ame-1.0/arguments.rb +44 -0
  7. data/lib/ame-1.0/arguments/complete.rb +37 -0
  8. data/lib/ame-1.0/arguments/optional.rb +34 -0
  9. data/lib/ame-1.0/arguments/undefined.rb +71 -0
  10. data/lib/ame-1.0/class.rb +436 -0
  11. data/lib/ame-1.0/flag.rb +101 -0
  12. data/lib/{ame → ame-1.0}/help.rb +1 -1
  13. data/lib/ame-1.0/help/delegate.rb +19 -0
  14. data/lib/ame-1.0/help/terminal.rb +132 -0
  15. data/lib/ame-1.0/method.rb +75 -0
  16. data/lib/ame-1.0/method/undefined.rb +184 -0
  17. data/lib/ame-1.0/methods.rb +40 -0
  18. data/lib/ame-1.0/multioption.rb +36 -0
  19. data/lib/ame-1.0/option.rb +37 -0
  20. data/lib/ame-1.0/optional.rb +31 -0
  21. data/lib/ame-1.0/options.rb +68 -0
  22. data/lib/ame-1.0/options/undefined.rb +114 -0
  23. data/lib/ame-1.0/root.rb +174 -0
  24. data/lib/ame-1.0/splat.rb +16 -0
  25. data/lib/ame-1.0/splus.rb +22 -0
  26. data/lib/ame-1.0/switch.rb +39 -0
  27. data/lib/ame-1.0/types.rb +60 -0
  28. data/lib/ame-1.0/types/boolean.rb +13 -0
  29. data/lib/ame-1.0/types/enumeration.rb +40 -0
  30. data/lib/ame-1.0/types/float.rb +11 -0
  31. data/lib/{ame → ame-1.0}/types/integer.rb +3 -3
  32. data/lib/{ame → ame-1.0}/types/string.rb +2 -2
  33. data/lib/ame-1.0/types/symbol.rb +9 -0
  34. data/lib/ame-1.0/version.rb +62 -0
  35. data/test/unit/ame-1.0.rb +4 -0
  36. data/test/unit/ame-1.0/argument.rb +46 -0
  37. data/test/unit/ame-1.0/arguments.rb +63 -0
  38. data/test/unit/ame-1.0/arguments/complete.rb +4 -0
  39. data/test/unit/ame-1.0/arguments/optional.rb +4 -0
  40. data/test/unit/ame-1.0/arguments/undefined.rb +63 -0
  41. data/test/unit/ame-1.0/class.rb +4 -0
  42. data/test/unit/ame-1.0/flag.rb +31 -0
  43. data/test/unit/ame-1.0/help.rb +4 -0
  44. data/test/unit/ame-1.0/help/delegate.rb +4 -0
  45. data/test/unit/{ame/help/console.rb → ame-1.0/help/terminal.rb} +34 -23
  46. data/test/unit/ame-1.0/method.rb +4 -0
  47. data/test/unit/ame-1.0/method/undefined.rb +33 -0
  48. data/test/unit/ame-1.0/methods.rb +9 -0
  49. data/test/unit/ame-1.0/multioption.rb +4 -0
  50. data/test/unit/ame-1.0/option.rb +11 -0
  51. data/test/unit/ame-1.0/optional.rb +9 -0
  52. data/test/unit/ame-1.0/options.rb +149 -0
  53. data/test/unit/ame-1.0/options/undefined.rb +33 -0
  54. data/test/unit/ame-1.0/root.rb +4 -0
  55. data/test/unit/ame-1.0/splat.rb +9 -0
  56. data/test/unit/ame-1.0/splus.rb +4 -0
  57. data/test/unit/ame-1.0/switch.rb +15 -0
  58. data/test/unit/ame-1.0/types.rb +4 -0
  59. data/test/{ame → unit/ame-1.0}/types/boolean.rb +0 -0
  60. data/test/unit/ame-1.0/types/enumeration.rb +4 -0
  61. data/test/unit/ame-1.0/types/float.rb +7 -0
  62. data/test/{ame → unit/ame-1.0}/types/integer.rb +0 -0
  63. data/test/{ame → unit/ame-1.0}/types/string.rb +0 -0
  64. data/test/unit/ame-1.0/types/symbol.rb +5 -0
  65. data/test/unit/ame-1.0/version.rb +4 -0
  66. metadata +690 -60
  67. data/lib/ame.rb +0 -26
  68. data/lib/ame/argument.rb +0 -56
  69. data/lib/ame/arguments.rb +0 -65
  70. data/lib/ame/class.rb +0 -117
  71. data/lib/ame/help/console.rb +0 -96
  72. data/lib/ame/method.rb +0 -94
  73. data/lib/ame/methods.rb +0 -30
  74. data/lib/ame/option.rb +0 -50
  75. data/lib/ame/options.rb +0 -102
  76. data/lib/ame/root.rb +0 -57
  77. data/lib/ame/splat.rb +0 -12
  78. data/lib/ame/types.rb +0 -29
  79. data/lib/ame/types/array.rb +0 -16
  80. data/lib/ame/types/boolean.rb +0 -16
  81. data/lib/ame/version.rb +0 -5
  82. data/test/ame/types/array.rb +0 -13
  83. data/test/unit/ame/argument.rb +0 -66
  84. data/test/unit/ame/arguments.rb +0 -106
  85. data/test/unit/ame/method.rb +0 -40
  86. data/test/unit/ame/methods.rb +0 -10
  87. data/test/unit/ame/option.rb +0 -75
  88. data/test/unit/ame/options.rb +0 -136
  89. data/test/unit/ame/root.rb +0 -15
  90. data/test/unit/ame/splat.rb +0 -11
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect ArgumentError.new('both short and long can’t be empty') do
5
+ Ame::Flag.new('', '', false, 'd')
6
+ end
7
+
8
+ expect ArgumentError.new('short can’t be longer than 1: abc') do
9
+ Ame::Flag.new('abc', '', false, 'd')
10
+ end
11
+
12
+ expect TrueClass do
13
+ Ame::Flag.new('a', '', false, 'd').process({}, [], '--a', 'true')
14
+ end
15
+
16
+ expect FalseClass do
17
+ Ame::Flag.new('a', '', false, 'd').process({}, [], '--a', 'off')
18
+ end
19
+
20
+ expect 'a' do
21
+ Ame::Flag.new('a', '', false, 'd').name
22
+ end
23
+
24
+ expect 'abc' do
25
+ Ame::Flag.new('', 'abc', false, 'd').name
26
+ end
27
+
28
+ expect 'abc' do
29
+ Ame::Flag.new('a', 'abc', false, 'd').name
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -10,22 +10,29 @@ Arguments:
10
10
  ARGN... Argument N
11
11
 
12
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
13
+ -a, --abc=ABC Abc description
14
+ --bcc=ADDRESS* Specify a Bcc: value for each email
15
+ --help Display help for this method
16
+ -s, --signoff Add Signed-off-by: line to the commit message
17
+ --thread[=STYLE] Controls addition of In-Reply-To and References headers
18
+ -v V description
19
+ --version Display version information
20
+ -xLEVEL X description
18
21
  }) do |io|
19
22
  Class.new(Ame::Root) {
20
- help Ame::Help::Console.new(io, false)
23
+ version '1.0.0'
24
+ help Ame::Help::Terminal.new(io, io, false)
21
25
 
22
26
  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'
27
+ option 'a', 'abc', 'abc', '', 'Abc description'
28
+ flag 'v', '', false, 'V description'
29
+ toggle 's', 'signoff', false, 'Add Signed-off-by: line to the commit message'
30
+ switch '', 'thread', 'style', nil, :shallow, 'Controls addition of In-Reply-To and References headers'
31
+ option 'x', '', 'level', '', 'X description'
32
+ multioption '', 'bcc', 'address', String, 'Specify a Bcc: value for each email'
33
+ argument 'arg1', String, 'Argument 1'
34
+ argument 'arg2', String, 'Argument 2'
35
+ splus 'argN', String, 'Argument N'
29
36
  def help_console_test_1() end
30
37
  }.process('help-console-test-1', %w[--help])
31
38
  end
@@ -38,15 +45,16 @@ Arguments:
38
45
  [ARGUMENTS]... Arguments to pass to METHOD
39
46
 
40
47
  Options:
41
- --help Display help for this method
42
- --version Display version information
48
+ --help Display help for this method
49
+ --version Display version information
43
50
 
44
51
  Methods:
45
52
  method-1 Method 1 does a
46
53
  method-2 Method 2 does b
47
54
  }) do |io|
48
55
  Class.new(Ame::Root) {
49
- help Ame::Help::Console.new(io, false)
56
+ version '1.0.0'
57
+ help Ame::Help::Terminal.new(io, io, false)
50
58
 
51
59
  dispatch Class.new(Ame::Class) {
52
60
  basename 'dispatch'
@@ -71,14 +79,15 @@ Arguments:
71
79
  [ARGUMENTS]... Arguments to pass to METHOD
72
80
 
73
81
  Options:
74
- --help Display help for this method
82
+ --help Display help for this method
75
83
 
76
84
  Methods:
77
85
  method-1 Method 1 does a
78
86
  method-2 Method 2 does b
79
87
  }) do |io|
80
88
  Class.new(Ame::Root) {
81
- help Ame::Help::Console.new(io, false)
89
+ version '1.0.0'
90
+ help Ame::Help::Terminal.new(io, io, false)
82
91
 
83
92
  dispatch Class.new(Ame::Class) {
84
93
  basename 'dispatch-1'
@@ -110,15 +119,16 @@ Arguments:
110
119
  [ARGUMENTS]... Arguments to pass to METHOD
111
120
 
112
121
  Options:
113
- --help Display help for this method
114
- --version Display version information
122
+ --help Display help for this method
123
+ --version Display version information
115
124
 
116
125
  Methods:
117
126
  method-1 Method 1 does a
118
127
  method-2 Method 2 does b
119
128
  }) do |io|
120
129
  Class.new(Ame::Root) {
121
- help Ame::Help::Console.new(io, false)
130
+ version '1.0.0'
131
+ help Ame::Help::Terminal.new(io, io, false)
122
132
 
123
133
  dispatch Class.new(Ame::Class) {
124
134
  basename 'dispatch'
@@ -137,9 +147,9 @@ Methods:
137
147
 
138
148
  expect output(%{method 0.1.0\n}) do |io|
139
149
  Class.new(Ame::Root) {
140
- Version = '0.1.0'
150
+ version '0.1.0'
141
151
 
142
- help Ame::Help::Console.new(io)
152
+ help Ame::Help::Terminal.new(io, io)
143
153
 
144
154
  description 'd'
145
155
  def method() end
@@ -149,7 +159,8 @@ Methods:
149
159
  expect output("method: error message\n") do |io|
150
160
  begin
151
161
  Class.new(Ame::Root) {
152
- help Ame::Help::Console.new(io, false)
162
+ version '1.0.0'
163
+ help Ame::Help::Terminal.new(io, io, false)
153
164
 
154
165
  description 'd'
155
166
  def method()
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect 'd' do Ame::Method::Undefined.new(nil).description('d').description end
5
+
6
+ expect result.not.valid? do Ame::Method::Undefined.new(nil) end
7
+ expect result.valid? do Ame::Method::Undefined.new(nil).description('d') end
8
+
9
+ expect 'name' do Ame::Method::Undefined.new(nil).description('d').define(:name).name end
10
+
11
+ expect mock.to.receive.method('b', 1, true, ['d', 'e', 'f'], {'a' => true}).once do |o|
12
+ Ame::Method::Undefined.new(o).
13
+ flag('a', '', false, 'd').
14
+ argument(:a, String, 'd').
15
+ argument(:b, Integer, 'd').
16
+ argument(:c, FalseClass, 'd').
17
+ splus(:d, String, 'd').
18
+ description('d').
19
+ define(:method).
20
+ process o, %w[b -a 1 on d e f]
21
+ end
22
+
23
+ expect mock.to.receive.method(1, false, [], {'a' => true}).once do |o|
24
+ Ame::Method::Undefined.new(o).
25
+ flag('a', '', true, 'd').
26
+ optional(:b, 1, 'd').
27
+ optional(:c, false, 'd').
28
+ splat(:d, 'd', :optional => true).
29
+ description('d').
30
+ define(:method).
31
+ call o
32
+ end
33
+ end
@@ -0,0 +1,9 @@
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::Undefined.new(nil).define(:name) end
7
+
8
+ expect Ame::Method::Undefined.new(nil).define(:name) do |o| (Ame::Methods.new << o)['name'] end
9
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect 'string' do
5
+ Ame::Option.new('a', '', 'a', '', 'd').process({}, [], '--a', 'string')
6
+ end
7
+
8
+ expect 'A' do
9
+ Ame::Option.new('a', '', 'a', '', 'd').argument
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect nil do Ame::Optional.new(:a, nil, 'd').process({}, [], []) end
5
+ expect 'default' do Ame::Optional.new(:a, 'default', 'd').process({}, [], []) end
6
+ expect 2 do Ame::Optional.new(:a, 1, 'd').process({}, [], ['2']) end
7
+ expect TrueClass do Ame::Optional.new(:a, true, 'd').process({}, [], []) end
8
+ expect FalseClass do Ame::Optional.new(:a, false, 'd').process({}, [], []) end
9
+ end
@@ -0,0 +1,149 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect Enumerable do
5
+ Ame::Options::Undefined.new.define
6
+ end
7
+
8
+ expect ['a', 'b'] do
9
+ Ame::Options::Undefined.new.flag('a', '', false, 'd').flag('b', '', false, 'd').define.map{ |o| o.name }
10
+ end
11
+
12
+ expect [{'a' => 1, 'b' => 2}, []] do
13
+ Ame::Options::Undefined.new.
14
+ option('a', '', 'A', 1, 'd').
15
+ option('b', '', 'B', 2, 'd').
16
+ define.
17
+ process([])
18
+ end
19
+
20
+ expect [{'a' => 3, 'b' => 4}, []] do
21
+ Ame::Options::Undefined.new.
22
+ option('a', '', 'A', 1, 'd').
23
+ option('b', '', 'B', 2, 'd').
24
+ define.
25
+ process(['-a=3', '-b=4'])
26
+ end
27
+
28
+ expect [{'a' => 3, 'b' => 4}, []] do
29
+ Ame::Options::Undefined.new.
30
+ option('a', '', 'A', 1, 'd').
31
+ option('b', '', 'B', 2, 'd').
32
+ define.
33
+ process(['-a', '3', '-b', '4'])
34
+ end
35
+
36
+ expect Ame::MalformedArgument do
37
+ Ame::Options::Undefined.new.option('a', '', 'A', 1, 'd').define.process(['-a='])
38
+ end
39
+
40
+ expect Ame::MissingArgument do
41
+ Ame::Options::Undefined.new.option('a', '', 'A', 1, 'd').define.process(['-a'])
42
+ end
43
+
44
+ expect Ame::UnrecognizedOption do
45
+ Ame::Options::Undefined.new.option('a', '', 'A', 1, 'd').define.process(['-b'])
46
+ end
47
+
48
+ expect Ame::MalformedArgument do
49
+ Ame::Options::Undefined.new.
50
+ option('a', '', 'A', 1, 'd').
51
+ option('b', '', 'B', 2, 'd').
52
+ define.
53
+ process(['-ab'])
54
+ end
55
+
56
+ expect Ame::MissingArgument do
57
+ Ame::Options::Undefined.new.
58
+ flag('a', '', false, 'd').
59
+ option('b', '', 'B', 2, 'd').
60
+ define.
61
+ process(['-ab'])
62
+ end
63
+
64
+ expect [{'a' => true, 'b' => 3}, []] do
65
+ Ame::Options::Undefined.new.
66
+ flag('a', '', false, 'd').
67
+ option('b', '', 'B', 2, 'd').
68
+ define.
69
+ process(['-ab3'])
70
+ end
71
+
72
+ expect [{'a' => true, 'b' => 3}, []] do
73
+ Ame::Options::Undefined.new.
74
+ flag('a', '', false, 'd').
75
+ option('b', '', 'B', 2, 'd').
76
+ define.
77
+ process(['-ab', '3'])
78
+ end
79
+
80
+ expect [{'a' => true, 'b' => true}, []] do
81
+ Ame::Options::Undefined.new.
82
+ flag('a', '', false, 'd').
83
+ flag('b', '', false, 'd').
84
+ define.
85
+ process(['-ab'])
86
+ end
87
+
88
+ expect [{'a' => true, 'b' => true}, []] do
89
+ Ame::Options::Undefined.new.
90
+ flag('a', '', false, 'd').
91
+ flag('b', '', false, 'd').
92
+ define.
93
+ process(['-a', '-b'])
94
+ end
95
+
96
+ expect [{'a' => true, 'b' => false}, ['-b']] do
97
+ Ame::Options::Undefined.new.
98
+ flag('a', '', false, 'd').
99
+ flag('b', '', false, 'd').
100
+ define.
101
+ process(['-a', '--', '-b'])
102
+ end
103
+
104
+ expect [{'a' => true, 'b' => true}, ['arg']] do
105
+ stub(ENV).include?{ false }
106
+ Ame::Options::Undefined.new.
107
+ flag('a', '', false, 'd').
108
+ flag('b', '', false, 'd').
109
+ define.
110
+ process(['arg', '-a', '-b'])
111
+ end
112
+
113
+ expect [{'a' => false, 'b' => false}, ['arg', '-a', '-b']] do
114
+ Ame::Options::Undefined.new.
115
+ options_must_precede_arguments.
116
+ flag('a', '', false, 'd').
117
+ flag('b', '', false, 'd').
118
+ define.
119
+ process(['arg', '-a', '-b'])
120
+ end
121
+
122
+ expect [{'a' => true}, []] do
123
+ Ame::Options::Undefined.new.flag('b', 'a', false, 'd').define.process(['-b'])
124
+ end
125
+
126
+ expect [{'a' => false}, []] do
127
+ Ame::Options::Undefined.new.flag('a', '', true, 'd').define.process(['-a'])
128
+ end
129
+
130
+ expect [{'abc' => true}, []] do
131
+ Ame::Options::Undefined.new.flag('', 'abc', false, 'd').define.process(['--abc'])
132
+ end
133
+
134
+ expect [{'abc' => 1}, []] do
135
+ Ame::Options::Undefined.new.option('', 'abc', 'N', 0, 'd').define.process(['--abc=1'])
136
+ end
137
+
138
+ expect [{'abc' => 1}, []] do
139
+ Ame::Options::Undefined.new.option('', 'abc', 'N', 0, 'd').define.process(['--abc', '1'])
140
+ end
141
+
142
+ expect [{}, []] do
143
+ Ame::Options::Undefined.new.flag('', 'abc', nil, 'd').define.process(['--abc'])
144
+ end
145
+
146
+ expect [{'a' => [1, 2, 3]}, []] do
147
+ Ame::Options::Undefined.new.multioption('a', '', 'N', Integer, 'd').define.process(%w[-a 1 -a 2 -a 3])
148
+ end
149
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect ArgumentError.new('option already defined: a') do
5
+ Ame::Options::Undefined.new.flag('a', '', false, 'd').flag('a', '', false, 'd')
6
+ end
7
+
8
+ expect result.include? 'a' do Ame::Options::Undefined.new.flag('a', '', false, 'd') end
9
+
10
+ expect({ 'signoff' => TrueClass }) do
11
+ Ame::Options::Undefined.new.toggle('s', 'signoff', false, 'd').define.process(['--signoff=true']).first
12
+ end
13
+
14
+ expect({ 'signoff' => FalseClass }) do
15
+ Ame::Options::Undefined.new.toggle('s', 'signoff', false, 'd').define.process(['--signoff=false']).first
16
+ end
17
+
18
+ expect({ 'signoff' => TrueClass }) do
19
+ Ame::Options::Undefined.new.toggle('s', 'signoff', false, 'd').define.process(['--signoff']).first
20
+ end
21
+
22
+ expect({ 'signoff' => FalseClass }) do
23
+ Ame::Options::Undefined.new.toggle('s', 'signoff', false, 'd').define.process(['--no-signoff']).first
24
+ end
25
+
26
+ expect Ame::MalformedArgument.new('--signoff: not a boolean: junk') do
27
+ Ame::Options::Undefined.new.toggle('s', 'signoff', false, 'd').define.process(['--signoff=junk']).first
28
+ end
29
+
30
+ expect Ame::MalformedArgument.new('--no-signoff: not a boolean: junk') do
31
+ Ame::Options::Undefined.new.toggle('s', 'signoff', false, 'd').define.process(['--no-signoff=junk']).first
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect Ame::MissingArgument do Ame::Splus.new('a', String, 'd').process({}, [], []) end
5
+
6
+ expect [] do Ame::Splat.new('a', String, 'd').process({}, [], []) end
7
+ expect ['arg'] do Ame::Splat.new('a', String, 'd').process({}, [], %w[arg]) end
8
+ expect [1, 2] do Ame::Splat.new('a', Integer, 'd').process({}, [], %w[1 2]) end
9
+ end