cli 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,9 +8,87 @@ Command Line Interface gem allows you to quickly specify command argument parser
8
8
 
9
9
  ## Examples
10
10
 
11
+ ### HTTPClient example
12
+
13
+ The following example shows basic usage of the CLI gem.
14
+ It will use HTTPClient to connect to server that address and port can be specified with `--server` and `--port` switches.
15
+ It expects at least one argument specifying the URL (that needs to start with `/`) and optional set of POST arguments.
16
+
17
+ ```ruby
18
+ re 'rubygems'
19
+ require 'cli'
20
+ require 'httpclient'
21
+
22
+ options = CLI.new do
23
+ option :server, :description => 'server address', :default => 'www.google.com'
24
+ option :port, :description => 'server port', :cast => Integer, :default => 80
25
+ argument :url, :description => 'URL to GET or POST to if arguments are given'
26
+ arguments :post_arguments, :required => false
27
+ end.parse! do |options|
28
+ fail "invalid URL '#{options.url}', URL has to start with '/'" unless options.url =~ /^\//
29
+ end
30
+
31
+ c = HTTPClient.new
32
+
33
+ begin
34
+ if options.post_arguments.empty?
35
+ puts c.get_async("http://#{options.server}:#{options.port}#{options.url}").pop.content.read
36
+ else
37
+ puts c.post_async("http://#{options.server}:#{options.port}#{options.url}", options.post_arguments.join("\n")).pop.content.read
38
+ end
39
+ rescue SocketError, Errno::ECONNREFUSED => e
40
+ puts "Falied to connect: #{e}"
41
+ end
42
+ ```
43
+
44
+ Example usage with default server:
45
+
46
+ examples/httpclient /index.html
47
+
48
+ The output will contain Google website.
49
+
50
+ Using different server:
51
+
52
+ examples/httpclient --server ibm.com /index.html
53
+
54
+ When run without arguments:
55
+
56
+ examples/httpclient
57
+
58
+ The following message will be printed and the program will exit (status 42):
59
+
60
+ Error: mandatory argument 'url' not given
61
+ Usage: httpclient [switches|options] [--] url [post-arguments*]
62
+ Switches:
63
+ --help (-h) - display this help message
64
+ Options:
65
+ --server [www.google.com] - server address
66
+ --port [80] - server port
67
+ Arguments:
68
+ url - URL to GET or POST to if arguments are given
69
+ post-arguments* (optional)
70
+
71
+ When used with command that does not start with `/`:
72
+
73
+ examples/httpclient test
74
+
75
+ It will print the following message and exit:
76
+
77
+ Error: invalid URL 'test', URL has to start with '/'
78
+ Usage: httpclient [switches|options] [--] url [post-arguments*]
79
+ Switches:
80
+ --help (-h) - display this help message
81
+ Options:
82
+ --server [www.google.com] - server address
83
+ --port [80] - server port
84
+ Arguments:
85
+ url - URL to GET or POST to if arguments are given
86
+ post-arguments* (optional)
87
+
11
88
  ### Sinatra server example
12
89
 
13
90
  ```ruby
91
+ require 'rubygems'
14
92
  require 'cli'
15
93
  require 'ip'
16
94
 
@@ -84,6 +162,7 @@ Example version output:
84
162
  ### Statistic data processor example
85
163
 
86
164
  ```ruby
165
+ require 'rubygems'
87
166
  require 'cli'
88
167
  require 'pathname'
89
168
  require 'yaml'
@@ -106,7 +185,7 @@ p options
106
185
 
107
186
  Example help message:
108
187
 
109
- Usage: processor [switches|options] [--] jekyll-dir < log-data
188
+ Usage: processor [switches|options] [--] [jekyll-dir] < log-data
110
189
  Generate blog posts in given Jekyll directory from input statistics
111
190
  Input:
112
191
  log-data - statistic data in YAML format
@@ -116,7 +195,7 @@ Example help message:
116
195
  --location (-l) - location name (ex. Dublin, Singapore, Califorina)
117
196
  --csv-dir (-c) [csv] - directory name where CSV file will be storred (relative to jekyll-dir)
118
197
  Arguments:
119
- jekyll-dir - directory where site source is located
198
+ jekyll-dir [/var/lib/vhs/jekyll] - directory where site source is located
120
199
 
121
200
  With this example usage (assuming /var/lib/vhs/jekyll/csv dir exist):
122
201
 
@@ -133,7 +212,7 @@ The `options` variable will contain:
133
212
  Output if jekyll-dir does not exist:
134
213
 
135
214
  Error: jekyll-dir is not a directory
136
- Usage: processor [switches|options] [--] jekyll-dir < log-data
215
+ Usage: processor [switches|options] [--] [jekyll-dir] < log-data
137
216
  Generate blog posts in given Jekyll directory from input statistics
138
217
  Input:
139
218
  log-data - statistic data in YAML format
@@ -155,6 +234,7 @@ Default and mandatory arguments will have priority on matching values (see specs
155
234
  The `options` specifier matched value will always be an array of casted elements or empty if option not specified.
156
235
 
157
236
  ```ruby
237
+ require 'rubygems'
158
238
  require 'cli'
159
239
  require 'pathname'
160
240
 
@@ -182,7 +262,7 @@ end
182
262
 
183
263
  Example help message:
184
264
 
185
- Usage: ls [switches|options] [--] directories*
265
+ Usage: ls [switches|options] [--] [directories*]
186
266
  Lists content of directories
187
267
  Switches:
188
268
  --long (-l) - use long listing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/cli.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cli"
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jakub Pastuszek"]
12
- s.date = "2011-12-31"
12
+ s.date = "2012-01-02"
13
13
  s.description = "Command Line Interface gem allows you to quickly specify command argument parser that will automatically generate usage, handle stdin, switches, options and arguments with default values and value casting"
14
14
  s.email = "jpastuszek@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "cli.gemspec",
29
+ "examples/httpclient",
29
30
  "examples/ls",
30
31
  "examples/processor",
31
32
  "examples/sinatra",
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'cli'
4
+ require 'httpclient'
5
+
6
+ options = CLI.new do
7
+ option :server, :description => 'server address', :default => 'www.google.com'
8
+ option :port, :description => 'server port', :cast => Integer, :default => 80
9
+ argument :url, :description => 'URL to GET or POST to if arguments are given'
10
+ arguments :post_arguments, :required => false
11
+ end.parse! do |options|
12
+ fail "invalid URL '#{options.url}', URL has to start with '/'" unless options.url =~ /^\//
13
+ end
14
+
15
+ c = HTTPClient.new
16
+
17
+ begin
18
+ if options.post_arguments.empty?
19
+ puts c.get_async("http://#{options.server}:#{options.port}#{options.url}").pop.content.read
20
+ else
21
+ puts c.post_async("http://#{options.server}:#{options.port}#{options.url}", options.post_arguments.join("\n")).pop.content.read
22
+ end
23
+ rescue SocketError, Errno::ECONNREFUSED => e
24
+ puts "Falied to connect: #{e}"
25
+ end
26
+
data/examples/ls CHANGED
@@ -1,4 +1,5 @@
1
- #!/usr/bin/ruby -rrubygems
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
2
3
  require 'cli'
3
4
  require 'pathname'
4
5
 
data/examples/processor CHANGED
@@ -1,4 +1,5 @@
1
- #!/usr/bin/ruby -rrubygems
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
2
3
  require 'cli'
3
4
  require 'pathname'
4
5
  require 'yaml'
data/examples/sinatra CHANGED
@@ -1,20 +1,21 @@
1
- #!/usr/bin/ruby -rrubygems
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
2
3
  require 'cli'
3
4
  require 'ip'
4
5
 
5
6
  options = CLI.new do
6
7
  description 'Example CLI usage for Sinatra server application'
7
8
  version "1.0.0"
8
- switch :no_bind, :description => "Do not bind to TCP socket - useful with -s fastcgi option"
9
- switch :no_logging, :description => "Disable logging"
10
- switch :debug, :description => "Enable debugging"
9
+ switch :no_bind, :description => "Do not bind to TCP socket - useful with -s fastcgi option"
10
+ switch :no_logging, :description => "Disable logging"
11
+ switch :debug, :description => "Enable debugging"
11
12
  switch :no_optimization, :description => "Disable size hinting and related optimization (loading, prescaling)"
12
- option :bind, :short => :b, :default => '127.0.0.1', :cast => IP, :description => "HTTP server bind address - use 0.0.0.0 to bind to all interfaces"
13
- option :port, :short => :p, :default => 3100, :cast => Integer, :description => "HTTP server TCP port"
14
- option :server, :short => :s, :default => 'mongrel', :description => "Rack server handler like thin, mongrel, webrick, fastcgi etc."
15
- option :limit_memory, :default => 128*1024**2, :cast => Integer, :description => "Image cache heap memory size limit in bytes"
16
- option :limit_map, :default => 256*1024**2, :cast => Integer, :description => "Image cache memory mapped file size limit in bytes - used when heap memory limit is used up"
17
- option :limit_disk, :default => 0, :cast => Integer, :description => "Image cache temporary file size limit in bytes - used when memory mapped file limit is used up"
13
+ option :bind, :short => :b, :default => '127.0.0.1', :cast => IP, :description => "HTTP server bind address - use 0.0.0.0 to bind to all interfaces"
14
+ option :port, :short => :p, :default => 3100, :cast => Integer, :description => "HTTP server TCP port"
15
+ option :server, :short => :s, :default => 'mongrel', :description => "Rack server handler like thin, mongrel, webrick, fastcgi etc."
16
+ option :limit_memory, :default => 128*1024**2, :cast => Integer, :description => "Image cache heap memory size limit in bytes"
17
+ option :limit_map, :default => 256*1024**2, :cast => Integer, :description => "Image cache memory mapped file size limit in bytes - used when heap memory limit is used up"
18
+ option :limit_disk, :default => 0, :cast => Integer, :description => "Image cache temporary file size limit in bytes - used when memory mapped file limit is used up"
18
19
  end.parse!
19
20
 
20
21
  p options
data/lib/cli.rb CHANGED
@@ -234,15 +234,7 @@ class CLI
234
234
  # process arguments
235
235
  arguments = @arguments.dup
236
236
  while argument = arguments.shift
237
- value = if arguments.mandatory.length >= argv.length
238
- if argument.has_default?
239
- argument.default
240
- elsif not argument.mandatory?
241
- argument.multiple? ? [] : nil
242
- else
243
- raise ParsingError::MandatoryArgumentNotSpecifiedError.new(argument) if argv.empty?
244
- end
245
- else
237
+ value = if arguments.mandatory.length < argv.length
246
238
  arg = argv.shift
247
239
 
248
240
  if argument.multiple?
@@ -254,6 +246,14 @@ class CLI
254
246
  else
255
247
  arg
256
248
  end
249
+ else
250
+ if argument.has_default?
251
+ argument.default
252
+ elsif not argument.mandatory?
253
+ argument.multiple? ? [] : nil
254
+ else
255
+ raise ParsingError::MandatoryArgumentNotSpecifiedError.new(argument) if argv.empty?
256
+ end
257
257
  end
258
258
 
259
259
  values.value(argument, argument.cast(value))
@@ -298,11 +298,21 @@ class CLI
298
298
  out = StringIO.new
299
299
  out.puts msg if msg
300
300
  out.print "Usage: #{CLI.name}"
301
- out.print ' [switches|options]' if not @switches.empty? and not @options.empty?
302
- out.print ' [switches]' if not @switches.empty? and @options.empty?
303
- out.print ' [options]' if @switches.empty? and not @options.empty?
301
+ out.print ' [switches|options]' if not @switches.empty? and not @options.optional.empty?
302
+ out.print ' [switches]' if not @switches.empty? and @options.optional.empty?
303
+ out.print ' [options]' if @switches.empty? and not @options.optional.empty?
304
+ @options.mandatory.each do |o|
305
+ out.print " #{o.switch} <value>"
306
+ end
304
307
  out.print ' [--]' if not @arguments.empty? and (not @switches.empty? or not @options.empty?)
305
- out.print ' ' + @arguments.map{|a| a.multiple? ? a.to_s + '*': a.to_s}.join(' ') unless @arguments.empty?
308
+ out.print ' ' unless @arguments.empty?
309
+ out.print(@arguments.map do |a|
310
+ v = ''
311
+ v += '[' unless a.mandatory?
312
+ v += a.multiple? ? a.to_s + '*': a.to_s
313
+ v += ']' unless a.mandatory?
314
+ v
315
+ end.join(' '))
306
316
  out.print " < #{@stdin}" if @stdin
307
317
 
308
318
  out.puts
@@ -333,23 +343,24 @@ class CLI
333
343
  out.print " #{o.switch}*"
334
344
  end
335
345
  out.print " (#{o.switch_short})" if o.has_short?
346
+ out.print ' (mandatory)' if o.mandatory?
336
347
  out.print " [%s]" % o.default if o.has_default?
337
348
  out.print " - #{o.description}" if o.description?
338
349
  out.puts
339
350
  end
340
351
  end
341
352
 
342
- described_arguments = @arguments.select{|a| a.description?}
343
- unless described_arguments.empty?
353
+ unless @arguments.empty?
344
354
  out.puts "Arguments:"
345
- described_arguments.each do |a|
355
+ @arguments.each do |a|
346
356
  unless a.multiple?
347
357
  out.print " #{a}"
348
358
  else
349
359
  out.print " #{a}*"
350
360
  end
361
+ out.print ' (optional)' if not a.mandatory? and not a.has_default?
351
362
  out.print " [%s]" % (a.default.is_a?(Array) ? a.default.join(' ') : a.default) if a.has_default?
352
- out.print " - #{a.description}"
363
+ out.print " - #{a.description}" if a.description?
353
364
  out.puts
354
365
  end
355
366
  end
data/lib/cli/options.rb CHANGED
@@ -9,6 +9,10 @@ class CLI::Options < CLI::Switches
9
9
  select{|o| o.mandatory?}
10
10
  end
11
11
 
12
+ def optional
13
+ select{|o| not o.mandatory?}
14
+ end
15
+
12
16
  def multiple
13
17
  select{|a| a.multiple?}
14
18
  end
@@ -150,62 +150,21 @@ describe CLI do
150
150
  }.should raise_error CLI::ParserError::MultipleArgumentsSpecifierError, "only one 'arguments' specifier can be used, got: test1, test3"
151
151
  end
152
152
 
153
- it "should not require non mandatory argument" do
154
- ps = CLI.new do
155
- argument :log, :cast => Pathname
156
- argument :test, :required => false
157
- end.parse(['/tmp'])
158
- ps.log.should be_a Pathname
159
- ps.log.to_s.should == '/tmp'
160
- ps.test.should be_nil
161
- end
162
-
163
153
  describe "with defaults" do
164
- it "when not enought arguments given it should fill required arguments only with defaults" do
165
- ps = CLI.new do
166
- argument :log, :cast => Pathname, :default => '/tmp'
167
- argument :test
168
- end.parse(['hello'])
169
- ps.log.should be_a Pathname
170
- ps.log.to_s.should == '/tmp'
171
- ps.test.should be_a String
172
- ps.test.should == 'hello'
173
-
174
- ps = CLI.new do
175
- argument :log, :cast => Pathname
176
- argument :test, :default => 'hello'
177
- end.parse(['/tmp'])
178
- ps.log.should be_a Pathname
179
- ps.log.to_s.should == '/tmp'
180
- ps.test.should be_a String
181
- ps.test.should == 'hello'
182
-
183
- ps = CLI.new do
184
- argument :log, :cast => Pathname
185
- argument :magick, :default => 'word'
186
- argument :test
187
- argument :code, :cast => Integer, :default => '123'
188
- end.parse(['/tmp', 'hello'])
189
- ps.log.to_s.should == '/tmp'
190
- ps.magick.should == 'word'
191
- ps.test.should == 'hello'
192
- ps.code.should == 123
193
-
154
+ it "should fill defaults form the beginning if more than required arguments are given" do
194
155
  ps = CLI.new do
195
- argument :log, :cast => Pathname
196
- argument :magick, :default => 'word'
197
- argument :test0, :required => false
198
- argument :test
199
- argument :code, :cast => Integer, :default => '123'
200
- end.parse(['/tmp', 'hello'])
201
- ps.log.to_s.should == '/tmp'
202
- ps.magick.should == 'word'
203
- ps.test0.should be_nil
204
- ps.test.should == 'hello'
205
- ps.code.should == 123
206
- end
156
+ argument :test1, :default => 'x'
157
+ argument :test2
158
+ argument :test3, :default => 'c'
159
+ argument :test4, :default => 'd'
160
+ argument :test5, :default => 'e'
161
+ end.parse(['a', 'b'])
162
+ ps.test1.should == 'a'
163
+ ps.test2.should == 'b'
164
+ ps.test3.should == 'c'
165
+ ps.test4.should == 'd'
166
+ ps.test5.should == 'e'
207
167
 
208
- it "should fill defaults form the beginning if more than required arguments are given" do
209
168
  ps = CLI.new do
210
169
  argument :log, :cast => Pathname
211
170
  argument :magick, :default => 'word'
@@ -272,7 +231,56 @@ describe CLI do
272
231
  ps.code.should == 123
273
232
  end
274
233
 
275
- it "should use empty array of values for multiple arguments argument when not enought arguments given" do
234
+ it "should fill at least one value of required multiple arguments argument" do
235
+ ps = CLI.new do
236
+ argument :test1, :default => 'x'
237
+ argument :test2, :default => 'b'
238
+ arguments :test3
239
+ argument :test4, :default => 'd'
240
+ argument :test5, :default => 'e'
241
+ end.parse(['a', 'c'])
242
+ ps.test1.should == 'a'
243
+ ps.test2.should == 'b'
244
+ ps.test3.should == ['c']
245
+ ps.test4.should == 'd'
246
+ ps.test5.should == 'e'
247
+ end
248
+ end
249
+
250
+ describe "not required" do
251
+ it "argument that is not required may be nil if there is not enought command arguments" do
252
+ ps = CLI.new do
253
+ argument :test1, :required => false
254
+ argument :test2, :required => false
255
+ argument :test3, :required => false
256
+ argument :test4, :required => false
257
+ argument :test5, :required => false
258
+ end.parse(['a', 'b'])
259
+ ps.test1.should == 'a'
260
+ ps.test2.should == 'b'
261
+ ps.test3.should be_nil
262
+ ps.test4.should be_nil
263
+ ps.test5.should be_nil
264
+
265
+ ps = CLI.new do
266
+ argument :log, :cast => Pathname
267
+ argument :test, :required => false
268
+ end.parse(['/tmp'])
269
+ ps.log.should be_a Pathname
270
+ ps.log.to_s.should == '/tmp'
271
+ ps.test.should be_nil
272
+ end
273
+
274
+ it "should use empty array for multiple arguments argument when not enought arguments given and it is not required" do
275
+ ps = CLI.new do
276
+ argument :test1, :required => false
277
+ argument :test2, :required => false
278
+ arguments :test3, :required => false
279
+ end.parse(['a', 'b'])
280
+ ps.test1.should == 'a'
281
+ ps.test2.should == 'b'
282
+ ps.test3.should == []
283
+
276
284
  ps = CLI.new do
277
285
  argument :log, :cast => Pathname
278
286
  argument :magick, :default => 'word'
data/spec/usage_spec.rb CHANGED
@@ -184,39 +184,79 @@ describe CLI do
184
184
  ss.usage.should include("4")
185
185
  end
186
186
 
187
- it "should suggest that arguments can be used in usage line" do
188
- ss = CLI.new do
189
- argument :location
187
+ describe "usage line" do
188
+ it "should suggest that arguments can be used in usage line" do
189
+ ss = CLI.new do
190
+ argument :location
191
+ end
192
+
193
+ # switches will always be there due to implicit --help switch
194
+ ss.usage.first.should == "Usage: rspec [switches] [--] location\n"
190
195
  end
191
196
 
192
- # switches will always be there due to implicit --help switch
193
- ss.usage.first.should == "Usage: rspec [switches] [--] location\n"
194
- end
197
+ it "should suggest that switches can be used in usage line" do
198
+ ss = CLI.new do
199
+ switch :location, :short => :l
200
+ end
195
201
 
196
- it "should suggest that switches can be used in usage line" do
197
- ss = CLI.new do
198
- switch :location, :short => :l
202
+ ss.usage.first.should == "Usage: rspec [switches]\n"
199
203
  end
200
204
 
201
- ss.usage.first.should == "Usage: rspec [switches]\n"
202
- end
205
+ it "should suggest that options can be used in usage line" do
206
+ ss = CLI.new do
207
+ option :location, :short => :l
208
+ end
203
209
 
204
- it "should suggest that options can be used in usage line" do
205
- ss = CLI.new do
206
- option :location, :short => :l
210
+ # switches will always be there due to implicit --help switch
211
+ ss.usage.first.should == "Usage: rspec [switches|options]\n"
207
212
  end
208
213
 
209
- # switches will always be there due to implicit --help switch
210
- ss.usage.first.should == "Usage: rspec [switches|options]\n"
211
- end
214
+ it "should suggest that switches or options can be used in usage line" do
215
+ ss = CLI.new do
216
+ switch :location, :short => :l
217
+ option :size, :short => :s
218
+ end
212
219
 
213
- it "should suggest that switches or options can be used in usage line" do
214
- ss = CLI.new do
215
- switch :location, :short => :l
216
- option :size, :short => :s
220
+ ss.usage.first.should == "Usage: rspec [switches|options]\n"
217
221
  end
218
222
 
219
- ss.usage.first.should == "Usage: rspec [switches|options]\n"
223
+ it "should suggest that option is mandatory" do
224
+ ss = CLI.new do
225
+ option :size, :required => true
226
+ option :group, :short => :g, :required => true
227
+ end
228
+
229
+ # switches will always be there due to implicit --help switch
230
+ ss.usage.first.should == "Usage: rspec [switches] --size <value> --group <value>\n"
231
+
232
+ ss = CLI.new do
233
+ option :location, :short => :l
234
+ option :size, :required => true
235
+ option :group, :short => :g, :required => true
236
+ end
237
+
238
+ # switches will always be there due to implicit --help switch
239
+ ss.usage.first.should == "Usage: rspec [switches|options] --size <value> --group <value>\n"
240
+
241
+ ss = CLI.new do
242
+ switch :location, :short => :l
243
+ option :size, :short => :s, :required => true
244
+ end
245
+
246
+ ss.usage.first.should == "Usage: rspec [switches] --size <value>\n"
247
+ end
248
+
249
+ it "should suggest that argument is optional" do
250
+ ss = CLI.new do
251
+ argument :location
252
+ argument :size, :required => false
253
+ argument :colour, :default => 'red'
254
+ argument :group
255
+ end
256
+
257
+ # switches will always be there due to implicit --help switch
258
+ ss.usage.first.should == "Usage: rspec [switches] [--] location [size] [colour] group\n"
259
+ end
220
260
  end
221
261
 
222
262
  it "should allow describing whole script" do
@@ -251,7 +291,7 @@ describe CLI do
251
291
  u.should include("log data to process")
252
292
  end
253
293
 
254
- it "should provide formated usage with optional message" do
294
+ it "should provide formated usage" do
255
295
  u = CLI.new do
256
296
  description 'Log file processor'
257
297
  version '1.0'
@@ -261,7 +301,7 @@ describe CLI do
261
301
  switch :run
262
302
  option :location, :short => :r, :description => "place where server is located"
263
303
  option :group, :default => 'red'
264
- options :power_up, :short => :p
304
+ options :power_up, :short => :p, :required => true
265
305
  option :speed, :short => :s, :cast => Integer
266
306
  option :the_number_of_the_beast, :short => :b, :cast => Integer, :default => 666, :description => "The number of the beast"
267
307
  option :size
@@ -269,14 +309,15 @@ describe CLI do
269
309
  argument :log, :cast => Pathname, :description => "log file to process"
270
310
  argument :magick, :default => 'word'
271
311
  argument :string
272
- argument :number, :cast => Integer
312
+ argument :limit, :cast => Integer, :required => false, :description => "limit in seconds"
313
+ argument :unlock_code, :cast => Integer, :required => false
273
314
  argument :code, :cast => Integer, :default => '123', :description => "secret code"
274
315
  argument :illegal_prime, :cast => Integer, :description => "prime number that represents information that it is forbidden to possess or distribute"
275
316
  arguments :files, :cast => Pathname, :default => ['test', '1', '2'], :description => "files to process"
276
317
  end.usage
277
318
 
278
319
  u.should == <<EOS
279
- Usage: rspec [switches|options] [--] log magick string number code illegal-prime files* < log-data
320
+ Usage: rspec [switches|options] --power-up <value> [--] log [magick] string [limit] [unlock-code] [code] illegal-prime [files*] < log-data
280
321
  Log file processor
281
322
  Input:
282
323
  log-data - YAML formatted log data
@@ -289,12 +330,16 @@ Switches:
289
330
  Options:
290
331
  --location (-r) - place where server is located
291
332
  --group [red]
292
- --power-up* (-p)
333
+ --power-up* (-p) (mandatory)
293
334
  --speed (-s)
294
335
  --the-number-of-the-beast (-b) [666] - The number of the beast
295
336
  --size
296
337
  Arguments:
297
338
  log - log file to process
339
+ magick [word]
340
+ string
341
+ limit (optional) - limit in seconds
342
+ unlock-code (optional)
298
343
  code [123] - secret code
299
344
  illegal-prime - prime number that represents information that it is forbidden to possess or distribute
300
345
  files* [test 1 2] - files to process
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jakub Pastuszek
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-31 00:00:00 Z
18
+ date: 2012-01-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development
@@ -142,6 +142,7 @@ files:
142
142
  - Rakefile
143
143
  - VERSION
144
144
  - cli.gemspec
145
+ - examples/httpclient
145
146
  - examples/ls
146
147
  - examples/processor
147
148
  - examples/sinatra