choosy 0.1.0 → 0.2.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.
Files changed (45) hide show
  1. data/README.markdown +229 -221
  2. data/Rakefile +21 -3
  3. data/examples/bar.rb +44 -0
  4. data/examples/foo.rb +198 -0
  5. data/examples/superfoo.rb +125 -0
  6. data/lib/VERSION +1 -1
  7. data/lib/choosy/argument.rb +51 -0
  8. data/lib/choosy/base_command.rb +22 -7
  9. data/lib/choosy/command.rb +12 -4
  10. data/lib/choosy/dsl/argument_builder.rb +88 -0
  11. data/lib/choosy/dsl/base_command_builder.rb +71 -56
  12. data/lib/choosy/dsl/command_builder.rb +14 -2
  13. data/lib/choosy/dsl/option_builder.rb +43 -83
  14. data/lib/choosy/dsl/super_command_builder.rb +37 -9
  15. data/lib/choosy/option.rb +13 -11
  16. data/lib/choosy/parse_result.rb +8 -27
  17. data/lib/choosy/parser.rb +20 -16
  18. data/lib/choosy/printing/color.rb +39 -21
  19. data/lib/choosy/printing/erb_printer.rb +12 -3
  20. data/lib/choosy/printing/formatting_element.rb +17 -0
  21. data/lib/choosy/printing/help_printer.rb +204 -117
  22. data/lib/choosy/printing/terminal.rb +53 -0
  23. data/lib/choosy/super_command.rb +6 -6
  24. data/lib/choosy/super_parser.rb +26 -15
  25. data/lib/choosy/verifier.rb +61 -6
  26. data/spec/choosy/base_command_spec.rb +27 -2
  27. data/spec/choosy/command_spec.rb +31 -9
  28. data/spec/choosy/dsl/argument_builder_spec.rb +180 -0
  29. data/spec/choosy/dsl/base_command_builder_spec.rb +87 -44
  30. data/spec/choosy/dsl/commmand_builder_spec.rb +15 -4
  31. data/spec/choosy/dsl/option_builder_spec.rb +101 -191
  32. data/spec/choosy/dsl/super_command_builder_spec.rb +34 -9
  33. data/spec/choosy/parser_spec.rb +30 -8
  34. data/spec/choosy/printing/color_spec.rb +19 -5
  35. data/spec/choosy/printing/help_printer_spec.rb +152 -73
  36. data/spec/choosy/printing/terminal_spec.rb +27 -0
  37. data/spec/choosy/super_command_spec.rb +17 -17
  38. data/spec/choosy/super_parser_spec.rb +20 -10
  39. data/spec/choosy/verifier_spec.rb +137 -47
  40. data/spec/integration/command-A_spec.rb +6 -6
  41. data/spec/integration/command-B_spec.rb +45 -0
  42. data/spec/integration/supercommand-A_spec.rb +33 -27
  43. data/spec/integration/supercommand-B_spec.rb +32 -0
  44. data/spec/spec_helpers.rb +8 -5
  45. metadata +95 -54
@@ -0,0 +1,45 @@
1
+ require 'choosy'
2
+ require 'spec_helpers'
3
+
4
+ describe "Command B" do
5
+ before :each do
6
+ @c = Choosy::Command.new :foo do
7
+ strings :many_args, "The many arguments"
8
+ help
9
+
10
+ arguments do
11
+ required
12
+ count 2..3
13
+ validate do |args, options|
14
+ if !args.include?("here")
15
+ die("Should have found 'here'")
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ it "should succeed when there are exactly three arguments" do
23
+ attempting {
24
+ @c.parse! ['this', 'is', 'here'], true
25
+ }.should_not raise_error
26
+ end
27
+
28
+ it "should fail when 'here' isn't in the argument list" do
29
+ attempting {
30
+ @c.parse! ['this', "isn't", 'happening'], true
31
+ }.should raise_error(Choosy::ValidationError, /'here'/)
32
+ end
33
+
34
+ it "should fail when there are too few arguments" do
35
+ attempting {
36
+ @c.parse! ['here'], true
37
+ }.should raise_error(Choosy::ValidationError, /too few/)
38
+ end
39
+
40
+ it "should fail when there are too many arguments" do
41
+ attempting {
42
+ @c.parse! ['here', 'is', 'a', 'list'], true
43
+ }.should raise_error(Choosy::ValidationError, /too many/)
44
+ end
45
+ end
@@ -1,39 +1,44 @@
1
1
  require 'spec_helpers'
2
2
  require 'choosy'
3
3
 
4
+ notes = {:this => 'here'}
5
+
4
6
  describe "SuperCommand A" do
5
7
  before :each do
6
- @cmd = Choosy::SuperCommand.new :superfoo do |foo|
7
- foo.desc "This is a supercommand of a definite size"
8
- foo.separator 'Commands:'
8
+ @cmd = Choosy::SuperCommand.new :superfoo do
9
+ para "This is a supercommand of a definite size"
10
+ header 'Commands:'
9
11
 
10
- foo.command :bar do |bar|
11
- bar.summary "This command is a bar"
12
- bar.desc "This is a description of this subcommand"
13
- bar.string :favorite_pet, "Your favorite pet."
14
- bar.boolean :Fuzzy, "Is your pet fuzzy?"
12
+ command :bar do
13
+ summary notes[:this]
14
+ para "This is a description of this subcommand"
15
+ string :favorite_pet, "Your favorite pet."
16
+ boolean :Fuzzy, "Is your pet fuzzy?"
15
17
  end
16
18
 
17
- foo.command :baz do |baz|
18
- baz.summary "This is a baz command"
19
- baz.desc "This is a description of baz"
20
- baz.boolean :accountant, "Your accountant who helps you cheat on your taxes"
21
- baz.integer :amount, "How much money do you save?"
19
+ command :baz do
20
+ summary "This is a baz command"
21
+ para "This is a description of baz"
22
+ boolean_ :accountant, "Your accountant who helps you cheat on your taxes"
23
+ integer :amount, "How much money do you save?"
22
24
  end
23
25
 
24
- foo.help
26
+ help
25
27
 
26
- foo.separator 'Options:'
27
- foo.version "1.ohyeah"
28
+ header 'Options:'
29
+ integer :count, "The Count" do
30
+ #required
31
+ end
32
+ version "1.ohyeah"
28
33
  end
29
34
  end
30
- =begin
35
+
31
36
  it "should fail when a command is not set" do
32
37
  o = capture :stderr do
33
38
  @cmd.parse! ['blah']
34
39
  end
35
40
 
36
- o.should match(/^superfoo: 'blah' is not a standard command/)
41
+ o.should match(/^superfoo: unrecognized command: 'blah'/)
37
42
  end
38
43
 
39
44
  it "should fail when parsing a non-existent option" do
@@ -41,21 +46,22 @@ describe "SuperCommand A" do
41
46
  @cmd.parse! ['--non-option']
42
47
  end
43
48
 
44
- o.should match(/^superfoo: '--non-option' is not a standard/)
49
+ o.should match(/^superfoo: unrecognized option: '--non-option'/)
45
50
  end
46
51
 
47
52
  it "should print the version with the given global flag" do
48
- o = capture :stdout do
49
- @cmd.parse! ['--version']
50
- end
51
-
53
+ o = capture { @cmd.parse! ['--version'] }
52
54
  o.should eql("1.ohyeah\n")
53
55
  end
54
56
 
55
57
  it "should correctly parse the bar command" do
56
- results = @cmd.parse! ['bar', '--favorite-pet', 'Blue']
57
- results.should have(1).item
58
- result[0].options.should eql({:favorite_pet => 'Blue', :Fuzzy => false})
58
+ result = @cmd.parse! ['bar', '--favorite-pet', 'Blue', '--count', '5']
59
+ result.subresults.should have(1).item
60
+ result.subresults[0].options.should eql({:favorite_pet => 'Blue', :Fuzzy => false, :count => 5})
61
+ end
62
+
63
+ it "should correctly print out the results of the 'help' command" do
64
+ o = capture { @cmd.parse! ['help'] }
65
+ o.should match(/Usage:/)
59
66
  end
60
- =end
61
67
  end
@@ -0,0 +1,32 @@
1
+ require 'choosy'
2
+ require 'spec_helpers'
3
+
4
+ describe "SuperCommand B" do
5
+ before :each do
6
+ @s = Choosy::SuperCommand.new :super do
7
+ header 'Commands:'
8
+ command :bar do
9
+ arguments do
10
+ count 0..1
11
+ end
12
+ end
13
+ command :foo
14
+ end
15
+ end
16
+
17
+ it "should leave 'foo' as an argument to bar when not parsimonious" do
18
+ res = @s.parse! ['bar', 'foo']
19
+ res.subresults.should have(1).items
20
+ res.subresults[0].args.should eql(['foo'])
21
+ end
22
+
23
+ it "should have 2 subresults when parsimonious" do
24
+ @s.alter do
25
+ parsimonious
26
+ end
27
+
28
+ res = @s.parse! ['bar', 'foo']
29
+ res.subresults.should have(2).items
30
+ res.subresults[0].args.should be_empty
31
+ end
32
+ end
@@ -21,10 +21,13 @@ def capture(kind=nil, &block)
21
21
  $stdout = original_stdout
22
22
  $stderr = original_stderr
23
23
  end
24
- res = {:stdout => fake_out.string, :stderr => fake_err.string}
25
- if kind
26
- res[kind]
27
- else
28
- res
24
+
25
+ case kind
26
+ when nil
27
+ fake_out.string
28
+ when :stderr
29
+ fake_err.string
30
+ when :stdout
31
+ fake_out.string
29
32
  end
30
33
  end
metadata CHANGED
@@ -1,70 +1,86 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: choosy
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Gabe McArthur
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2011-03-01 00:00:00.000000000 -08:00
16
+
17
+ date: 2011-03-07 00:00:00 -08:00
13
18
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- requirement: &69898880 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
18
24
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
23
31
  type: :development
24
- prerelease: false
25
- version_requirements: *69898880
26
- - !ruby/object:Gem::Dependency
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
27
34
  name: autotest
28
- requirement: &69898640 !ruby/object:Gem::Requirement
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
29
37
  none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
34
44
  type: :development
35
- prerelease: false
36
- version_requirements: *69898640
37
- - !ruby/object:Gem::Dependency
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
38
47
  name: autotest-notification
39
- requirement: &69898400 !ruby/object:Gem::Requirement
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
40
50
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
45
57
  type: :development
46
- prerelease: false
47
- version_requirements: *69898400
48
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
49
60
  name: rspec
50
- requirement: &69936700 !ruby/object:Gem::Requirement
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
51
63
  none: false
52
- requirements:
64
+ requirements:
53
65
  - - ~>
54
- - !ruby/object:Gem::Version
55
- version: '2.5'
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 2
69
+ - 5
70
+ version: "2.5"
56
71
  type: :development
57
- prerelease: false
58
- version_requirements: *69936700
72
+ version_requirements: *id004
59
73
  description: This is a DSL for creating more complicated command line tools.
60
- email:
74
+ email:
61
75
  - madeonamac@gmail.com
62
76
  executables: []
77
+
63
78
  extensions: []
64
- extra_rdoc_files:
79
+
80
+ extra_rdoc_files:
65
81
  - LICENSE
66
82
  - README.markdown
67
- files:
83
+ files:
68
84
  - Gemfile
69
85
  - Gemfile.lock
70
86
  - LICENSE
@@ -72,9 +88,11 @@ files:
72
88
  - Rakefile
73
89
  - lib/VERSION
74
90
  - lib/choosy.rb
91
+ - lib/choosy/argument.rb
75
92
  - lib/choosy/base_command.rb
76
93
  - lib/choosy/command.rb
77
94
  - lib/choosy/converter.rb
95
+ - lib/choosy/dsl/argument_builder.rb
78
96
  - lib/choosy/dsl/base_command_builder.rb
79
97
  - lib/choosy/dsl/command_builder.rb
80
98
  - lib/choosy/dsl/option_builder.rb
@@ -85,7 +103,9 @@ files:
85
103
  - lib/choosy/parser.rb
86
104
  - lib/choosy/printing/color.rb
87
105
  - lib/choosy/printing/erb_printer.rb
106
+ - lib/choosy/printing/formatting_element.rb
88
107
  - lib/choosy/printing/help_printer.rb
108
+ - lib/choosy/printing/terminal.rb
89
109
  - lib/choosy/super_command.rb
90
110
  - lib/choosy/super_parser.rb
91
111
  - lib/choosy/verifier.rb
@@ -93,6 +113,7 @@ files:
93
113
  - spec/choosy/base_command_spec.rb
94
114
  - spec/choosy/command_spec.rb
95
115
  - spec/choosy/converter_spec.rb
116
+ - spec/choosy/dsl/argument_builder_spec.rb
96
117
  - spec/choosy/dsl/base_command_builder_spec.rb
97
118
  - spec/choosy/dsl/commmand_builder_spec.rb
98
119
  - spec/choosy/dsl/option_builder_spec.rb
@@ -100,41 +121,58 @@ files:
100
121
  - spec/choosy/parser_spec.rb
101
122
  - spec/choosy/printing/color_spec.rb
102
123
  - spec/choosy/printing/help_printer_spec.rb
124
+ - spec/choosy/printing/terminal_spec.rb
103
125
  - spec/choosy/super_command_spec.rb
104
126
  - spec/choosy/super_parser_spec.rb
105
127
  - spec/choosy/verifier_spec.rb
106
128
  - spec/integration/command-A_spec.rb
129
+ - spec/integration/command-B_spec.rb
107
130
  - spec/integration/supercommand-A_spec.rb
131
+ - spec/integration/supercommand-B_spec.rb
108
132
  - spec/spec_helpers.rb
133
+ - examples/bar.rb
134
+ - examples/foo.rb
135
+ - examples/superfoo.rb
109
136
  has_rdoc: true
110
137
  homepage: http://github.com/gabemc/choosy
111
138
  licenses: []
139
+
112
140
  post_install_message:
113
141
  rdoc_options: []
114
- require_paths:
142
+
143
+ require_paths:
115
144
  - lib
116
- required_ruby_version: !ruby/object:Gem::Requirement
145
+ required_ruby_version: !ruby/object:Gem::Requirement
117
146
  none: false
118
- requirements:
119
- - - ! '>='
120
- - !ruby/object:Gem::Version
121
- version: '0'
122
- required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
154
  none: false
124
- requirements:
125
- - - ! '>='
126
- - !ruby/object:Gem::Version
127
- version: '0'
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ segments:
159
+ - 0
160
+ version: "0"
128
161
  requirements: []
162
+
129
163
  rubyforge_project:
130
- rubygems_version: 1.5.2
164
+ rubygems_version: 1.3.7
131
165
  signing_key:
132
166
  specification_version: 3
133
167
  summary: Yet another option parsing library.
134
- test_files:
168
+ test_files:
169
+ - examples/bar.rb
170
+ - examples/foo.rb
171
+ - examples/superfoo.rb
135
172
  - spec/choosy/base_command_spec.rb
136
173
  - spec/choosy/command_spec.rb
137
174
  - spec/choosy/converter_spec.rb
175
+ - spec/choosy/dsl/argument_builder_spec.rb
138
176
  - spec/choosy/dsl/base_command_builder_spec.rb
139
177
  - spec/choosy/dsl/commmand_builder_spec.rb
140
178
  - spec/choosy/dsl/option_builder_spec.rb
@@ -142,9 +180,12 @@ test_files:
142
180
  - spec/choosy/parser_spec.rb
143
181
  - spec/choosy/printing/color_spec.rb
144
182
  - spec/choosy/printing/help_printer_spec.rb
183
+ - spec/choosy/printing/terminal_spec.rb
145
184
  - spec/choosy/super_command_spec.rb
146
185
  - spec/choosy/super_parser_spec.rb
147
186
  - spec/choosy/verifier_spec.rb
148
187
  - spec/integration/command-A_spec.rb
188
+ - spec/integration/command-B_spec.rb
149
189
  - spec/integration/supercommand-A_spec.rb
190
+ - spec/integration/supercommand-B_spec.rb
150
191
  - spec/spec_helpers.rb