cli 1.2.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -7
  3. data/Gemfile.lock +29 -37
  4. data/README.md +43 -44
  5. data/Rakefile +1 -28
  6. data/cli.gemspec +14 -84
  7. data/examples/httpclient +6 -6
  8. data/examples/ls +4 -4
  9. data/examples/processor +5 -5
  10. data/examples/sinatra +9 -9
  11. data/lib/cli/dsl.rb +3 -3
  12. data/rdoc/CLI/Arguments.html +178 -0
  13. data/rdoc/CLI/DSL/Argument.html +200 -0
  14. data/rdoc/CLI/DSL/Arguments.html +172 -0
  15. data/rdoc/CLI/DSL/Base.html +154 -0
  16. data/rdoc/CLI/DSL/Cast.html +152 -0
  17. data/rdoc/CLI/DSL/Description.html +150 -0
  18. data/rdoc/CLI/DSL/Input.html +143 -0
  19. data/rdoc/CLI/DSL/MultiDefault.html +151 -0
  20. data/rdoc/CLI/DSL/Option.html +143 -0
  21. data/rdoc/CLI/DSL/Options.html +142 -0
  22. data/rdoc/CLI/DSL/Switch.html +267 -0
  23. data/rdoc/CLI/DSL/Value.html +238 -0
  24. data/rdoc/CLI/DSL.html +91 -0
  25. data/rdoc/CLI/Options.html +200 -0
  26. data/rdoc/CLI/ParserError/ArgumentNameSpecifiedTwice.html +138 -0
  27. data/rdoc/CLI/ParserError/LongNameSpecifiedTwiceError.html +138 -0
  28. data/rdoc/CLI/ParserError/MultipleArgumentsSpecifierError.html +138 -0
  29. data/rdoc/CLI/ParserError/NameArgumetNotSymbolError.html +138 -0
  30. data/rdoc/CLI/ParserError/OptionsArgumentNotHashError.html +138 -0
  31. data/rdoc/CLI/ParserError/ShortNameIsInvalidError.html +138 -0
  32. data/rdoc/CLI/ParserError/ShortNameNotSymbolError.html +138 -0
  33. data/rdoc/CLI/ParserError/ShortNameSpecifiedTwiceError.html +138 -0
  34. data/rdoc/CLI/ParserError.html +97 -0
  35. data/rdoc/CLI/ParsingError/CastError.html +138 -0
  36. data/rdoc/CLI/ParsingError/MandatoryArgumentNotSpecifiedError.html +138 -0
  37. data/rdoc/CLI/ParsingError/MandatoryOptionsNotSpecifiedError.html +138 -0
  38. data/rdoc/CLI/ParsingError/MissingOptionValueError.html +138 -0
  39. data/rdoc/CLI/ParsingError/UnknownSwitchError.html +138 -0
  40. data/rdoc/CLI/ParsingError/UsageError.html +97 -0
  41. data/rdoc/CLI/ParsingError.html +97 -0
  42. data/rdoc/CLI/Switches.html +306 -0
  43. data/rdoc/CLI/Values.html +202 -0
  44. data/rdoc/CLI.html +652 -0
  45. data/rdoc/README_md.html +553 -0
  46. data/rdoc/created.rid +7 -0
  47. data/rdoc/css/fonts.css +167 -0
  48. data/rdoc/css/rdoc.css +639 -0
  49. data/rdoc/fonts/Lato-Light.ttf +0 -0
  50. data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
  51. data/rdoc/fonts/Lato-Regular.ttf +0 -0
  52. data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
  53. data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
  54. data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
  55. data/rdoc/images/add.png +0 -0
  56. data/rdoc/images/arrow_up.png +0 -0
  57. data/rdoc/images/brick.png +0 -0
  58. data/rdoc/images/brick_link.png +0 -0
  59. data/rdoc/images/bug.png +0 -0
  60. data/rdoc/images/bullet_black.png +0 -0
  61. data/rdoc/images/bullet_toggle_minus.png +0 -0
  62. data/rdoc/images/bullet_toggle_plus.png +0 -0
  63. data/rdoc/images/date.png +0 -0
  64. data/rdoc/images/delete.png +0 -0
  65. data/rdoc/images/find.png +0 -0
  66. data/rdoc/images/loadingAnimation.gif +0 -0
  67. data/rdoc/images/macFFBgHack.png +0 -0
  68. data/rdoc/images/package.png +0 -0
  69. data/rdoc/images/page_green.png +0 -0
  70. data/rdoc/images/page_white_text.png +0 -0
  71. data/rdoc/images/page_white_width.png +0 -0
  72. data/rdoc/images/plugin.png +0 -0
  73. data/rdoc/images/ruby.png +0 -0
  74. data/rdoc/images/tag_blue.png +0 -0
  75. data/rdoc/images/tag_green.png +0 -0
  76. data/rdoc/images/transparent.png +0 -0
  77. data/rdoc/images/wrench.png +0 -0
  78. data/rdoc/images/wrench_orange.png +0 -0
  79. data/rdoc/images/zoom.png +0 -0
  80. data/rdoc/index.html +120 -0
  81. data/rdoc/js/darkfish.js +84 -0
  82. data/rdoc/js/navigation.js +105 -0
  83. data/rdoc/js/navigation.js.gz +0 -0
  84. data/rdoc/js/search.js +110 -0
  85. data/rdoc/js/search_index.js +1 -0
  86. data/rdoc/js/search_index.js.gz +0 -0
  87. data/rdoc/js/searcher.js +229 -0
  88. data/rdoc/js/searcher.js.gz +0 -0
  89. data/rdoc/table_of_contents.html +533 -0
  90. data/spec/argument_spec.rb +122 -99
  91. data/spec/cli_spec.rb +27 -28
  92. data/spec/conflict_reporting_spec.rb +16 -17
  93. data/spec/option_spec.rb +79 -56
  94. data/spec/separator_spec.rb +19 -20
  95. data/spec/stdin_spec.rb +13 -14
  96. data/spec/switch_spec.rb +15 -16
  97. data/spec/usage_spec.rb +80 -81
  98. metadata +91 -104
  99. data/.document +0 -5
  100. data/.rspec +0 -1
  101. data/VERSION +0 -1
  102. data/features/cli.feature +0 -9
  103. data/features/step_definitions/cli_steps.rb +0 -0
  104. data/features/support/env.rb +0 -13
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7cf21e138ef28582b6180c808de4905f792b2205a2bae357dee8c2070c1068b9
4
+ data.tar.gz: 447ee769df7594df66b621edcec8a741e22400831560973cb4db0c898fef01f0
5
+ SHA512:
6
+ metadata.gz: f7d41024d20971baf9fb26fd53b4f7ff0a71d74d74ab66f3aa5392a4544116191a26fb9d88a762fa2e6147d17c2095d4a19a721a3c6a04fc78cf5aaf605a1456
7
+ data.tar.gz: 8556eb061844dc0696ebca9a56db5bc38b12dc8d0f6c00961359693e2744f5c60733247866a53660e6e581600e8fad4d6d9efd10dab479d9cde601df0f09c714
data/Gemfile CHANGED
@@ -3,11 +3,9 @@ source "http://rubygems.org"
3
3
  # Add dependencies to develop your gem here.
4
4
  # Include everything needed to run rake, tests, features, etc.
5
5
  group :development do
6
- gem "rspec", "~> 2.4"
7
- gem "cucumber", ">= 0"
8
- gem "bundler", "~> 1.2"
9
- gem "jeweler", "~> 1.6.4"
10
- gem "rcov", ">= 0"
11
- gem "rdoc", "~> 3.9"
12
- gem "ruby-ip", "~> 0.9"
6
+ gem "rake", "~> 13.0"
7
+ gem "rspec", "~> 3.11"
8
+ gem "bundler", "~> 2.2"
9
+ gem "rdoc", "~> 6.4"
10
+ gem "ruby-ip", "~> 0.9.3"
13
11
  end
data/Gemfile.lock CHANGED
@@ -1,45 +1,37 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- builder (3.0.0)
5
- cucumber (1.1.3)
6
- builder (>= 2.1.2)
7
- diff-lcs (>= 1.1.2)
8
- gherkin (~> 2.6.7)
9
- json (>= 1.4.6)
10
- term-ansicolor (>= 1.0.6)
11
- diff-lcs (1.1.3)
12
- gherkin (2.6.8)
13
- json (>= 1.4.6)
14
- git (1.2.5)
15
- jeweler (1.6.4)
16
- bundler (~> 1.0)
17
- git (>= 1.2.5)
18
- rake
19
- json (1.6.2)
20
- rake (0.9.2.2)
21
- rcov (0.9.11)
22
- rdoc (3.11)
23
- json (~> 1.4)
24
- rspec (2.11.0)
25
- rspec-core (~> 2.11.0)
26
- rspec-expectations (~> 2.11.0)
27
- rspec-mocks (~> 2.11.0)
28
- rspec-core (2.11.1)
29
- rspec-expectations (2.11.3)
30
- diff-lcs (~> 1.1.3)
31
- rspec-mocks (2.11.2)
32
- ruby-ip (0.9.0)
33
- term-ansicolor (1.0.7)
4
+ diff-lcs (1.5.0)
5
+ psych (4.0.3)
6
+ stringio
7
+ rake (13.0.6)
8
+ rdoc (6.4.0)
9
+ psych (>= 4.0.0)
10
+ rspec (3.11.0)
11
+ rspec-core (~> 3.11.0)
12
+ rspec-expectations (~> 3.11.0)
13
+ rspec-mocks (~> 3.11.0)
14
+ rspec-core (3.11.0)
15
+ rspec-support (~> 3.11.0)
16
+ rspec-expectations (3.11.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.11.0)
19
+ rspec-mocks (3.11.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.11.0)
22
+ rspec-support (3.11.0)
23
+ ruby-ip (0.9.3)
24
+ stringio (3.0.1)
34
25
 
35
26
  PLATFORMS
36
27
  ruby
37
28
 
38
29
  DEPENDENCIES
39
- bundler (~> 1.2)
40
- cucumber
41
- jeweler (~> 1.6.4)
42
- rcov
43
- rdoc (~> 3.9)
44
- rspec (~> 2.4)
45
- ruby-ip (~> 0.9)
30
+ bundler (~> 2.2)
31
+ rake (~> 13.0)
32
+ rdoc (~> 6.4)
33
+ rspec (~> 3.11)
34
+ ruby-ip (~> 0.9.3)
35
+
36
+ BUNDLED WITH
37
+ 2.2.32
data/README.md CHANGED
@@ -15,29 +15,29 @@ It will use HTTPClient to connect to server that address and port can be specifi
15
15
  It expects at least one argument specifying the URL (that needs to start with `/`) and optional set of POST arguments.
16
16
 
17
17
  ```ruby
18
- re 'rubygems'
18
+ require 'rubygems'
19
19
  require 'cli'
20
20
  require 'httpclient'
21
21
 
22
- options = CLI.new do
22
+ settings = CLI.new do
23
23
  option :server, :description => 'server address', :default => 'www.google.com'
24
24
  option :port, :description => 'server port', :cast => Integer, :default => 80
25
25
  argument :url, :description => 'URL to GET or POST to if arguments are given'
26
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 =~ /^\//
27
+ end.parse! do |settings|
28
+ fail "invalid URL '#{settings.url}', URL has to start with '/'" unless settings.url =~ /^\//
29
29
  end
30
30
 
31
31
  c = HTTPClient.new
32
32
 
33
33
  begin
34
- if options.post_arguments.empty?
35
- puts c.get_async("http://#{options.server}:#{options.port}#{options.url}").pop.content.read
34
+ if settings.post_arguments.empty?
35
+ puts c.get_async("http://#{settings.server}:#{settings.port}#{settings.url}").pop.content.read
36
36
  else
37
- puts c.post_async("http://#{options.server}:#{options.port}#{options.url}", options.post_arguments.join("\n")).pop.content.read
38
- end
37
+ puts c.post_async("http://#{settings.server}:#{settings.port}#{settings.url}", settings.post_arguments.join("\n")).pop.content.read
38
+ end
39
39
  rescue SocketError, Errno::ECONNREFUSED => e
40
- puts "Falied to connect: #{e}"
40
+ puts "Failed to connect: #{e}"
41
41
  end
42
42
  ```
43
43
 
@@ -92,7 +92,7 @@ require 'rubygems'
92
92
  require 'cli'
93
93
  require 'ip'
94
94
 
95
- options = CLI.new do
95
+ settings = CLI.new do
96
96
  description 'Example CLI usage for Sinatra server application'
97
97
  version "1.0.0"
98
98
  switch :no_bind, :description => "Do not bind to TCP socket - useful with -s fastcgi option"
@@ -113,15 +113,15 @@ require 'sinatra/base'
113
113
  sinatra = Sinatra.new
114
114
 
115
115
  sinatra.set :environment, 'production'
116
- sinatra.set :server, options.server
116
+ sinatra.set :server, settings.server
117
117
  sinatra.set :lock, true
118
- sinatra.set :boundary, "thumnail image data"
119
- sinatra.set :logging, (not options.no_logging)
120
- sinatra.set :debug, options.debug
121
- sinatra.set :optimization, (not options.no_optimization)
122
- sinatra.set :limit_memory, options.limit_memory
123
- sinatra.set :limit_map, options.limit_map
124
- sinatra.set :limit_disk, options.limit_disk
118
+ sinatra.set :boundary, "thumbnail image data"
119
+ sinatra.set :logging, (not settings.no_logging)
120
+ sinatra.set :debug, settings.debug
121
+ sinatra.set :optimization, (not settings.no_optimization)
122
+ sinatra.set :limit_memory, settings.limit_memory
123
+ sinatra.set :limit_map, settings.limit_map
124
+ sinatra.set :limit_disk, settings.limit_disk
125
125
 
126
126
  # set up your application
127
127
 
@@ -167,18 +167,18 @@ require 'cli'
167
167
  require 'pathname'
168
168
  require 'yaml'
169
169
 
170
- options = CLI.new do
170
+ settings = CLI.new do
171
171
  description 'Generate blog posts in given Jekyll directory from input statistics'
172
172
  stdin :log_data, :cast => YAML, :description => 'statistic data in YAML format'
173
- option :location, :short => :l, :description => 'location name (ex. Dublin, Singapore, Califorina)'
174
- option :csv_dir, :short => :c, :cast => Pathname, :default => 'csv', :description => 'directory name where CSV file will be storred (relative to jekyll-dir)'
173
+ option :location, :short => :l, :description => 'location name (ex. Dublin, Singapore, California)'
174
+ option :csv_dir, :short => :c, :cast => Pathname, :default => 'csv', :description => 'directory name where CSV file will be stored (relative to jekyll-dir)'
175
175
  argument :jekyll_dir, :cast => Pathname, :default => '/var/lib/vhs/jekyll', :description => 'directory where site source is located'
176
- end.parse! do |options|
177
- fail 'jekyll-dir is not a directory' unless options.jekyll_dir.directory?
178
- fail '--csv-dir is not a directory (relative to jekyll-dir)' unless (options.jekyll_dir + options.csv_dir).directory?
176
+ end.parse! do |settings|
177
+ fail 'jekyll-dir is not a directory' unless settings.jekyll_dir.directory?
178
+ fail '--csv-dir is not a directory (relative to jekyll-dir)' unless (settings.jekyll_dir + settings.csv_dir).directory?
179
179
  end
180
180
 
181
- p options
181
+ p settings
182
182
 
183
183
  # do your stuff
184
184
  ```
@@ -192,20 +192,20 @@ Example help message:
192
192
  Switches:
193
193
  --help (-h) - display this help message
194
194
  Options:
195
- --location (-l) - location name (ex. Dublin, Singapore, Califorina)
196
- --csv-dir (-c) [csv] - directory name where CSV file will be storred (relative to jekyll-dir)
195
+ --location (-l) - location name (ex. Dublin, Singapore, California)
196
+ --csv-dir (-c) [csv] - directory name where CSV file will be stored (relative to jekyll-dir)
197
197
  Arguments:
198
198
  jekyll-dir [/var/lib/vhs/jekyll] - directory where site source is located
199
199
 
200
200
  With this example usage (assuming /var/lib/vhs/jekyll/csv dir exist):
201
201
 
202
202
  examples/processor --location Singapore <<EOF
203
- :parser:
203
+ :parser:
204
204
  :successes: 41
205
205
  :failures: 0
206
206
  EOF
207
207
 
208
- The `options` variable will contain:
208
+ The `settings` variable will contain:
209
209
 
210
210
  #<CLI::Values stdin={:parser=>{:successes=>41, :failures=>0}}, jekyll_dir=#<Pathname:/var/lib/vhs/jekyll>, csv_dir=#<Pathname:csv>, help=nil, location="Singapore">
211
211
 
@@ -238,20 +238,20 @@ require 'rubygems'
238
238
  require 'cli'
239
239
  require 'pathname'
240
240
 
241
- values = CLI.new do
241
+ settings = CLI.new do
242
242
  description 'Lists content of directories'
243
243
  switch :long, :short => :l, :description => 'use long listing'
244
244
  options :exclude, :short => :e, :description => 'exclude files from listing'
245
245
  arguments :directories, :cast => Pathname, :default => '.', :description => 'directories to list content of'
246
246
  end.parse!
247
247
 
248
- values.directories.each do |dir|
248
+ settings.directories.each do |dir|
249
249
  next unless dir.directory?
250
250
  dir.each_entry do |e|
251
251
  next if e.to_s == '.' or e.to_s == '..'
252
252
  e = dir + e
253
- next if values.exclude.include? e.to_s
254
- if values.long
253
+ next if settings.exclude.include? e.to_s
254
+ if settings.long
255
255
  puts "#{e.stat.uid}:#{e.stat.gid} #{e}"
256
256
  else
257
257
  puts e
@@ -303,7 +303,7 @@ Prints:
303
303
  ...
304
304
 
305
305
  With directory list:
306
-
306
+
307
307
  examples/ls *
308
308
 
309
309
  Prints:
@@ -320,7 +320,7 @@ Prints:
320
320
  pkg/cli-0.0.1.gem
321
321
  pkg/cli-0.0.2.gem
322
322
  ...
323
-
323
+
324
324
  Long printout:
325
325
 
326
326
  examples/ls -l *
@@ -339,7 +339,7 @@ Prints:
339
339
  501:20 pkg/cli-0.0.1.gem
340
340
  501:20 pkg/cli-0.0.2.gem
341
341
  ...
342
-
342
+
343
343
  ## Usage
344
344
 
345
345
  `CLI.new` takes a block where you specify parser behavior. The returned object is a parser that has `#parse` and `#parse!` methods.
@@ -350,7 +350,7 @@ It will take argument array (defaults to ARGV), standard input IO (defaults to S
350
350
 
351
351
  The method will parse argument array and cast standard input IO according to parser specification and return OpenStruct kind of object with resulting values.
352
352
 
353
- The returned object will have `help` attribute set if `--help` or `-h` switch was found in argument array or `version` attribute if `--version` argument was found.
353
+ The returned object will have `help` attribute set if `--help` or `-h` switch was found in argument array or `version` attribute if `--version` argument was found.
354
354
  In other case all the attributes will be set to appropriate values depending on argument array and parser specification.
355
355
  In case of parsing error `CLI::ParsingError` kind of exception will be raised.
356
356
 
@@ -389,9 +389,9 @@ The value after casting (if used) will be available from the `#parse` or `#parse
389
389
  In addition to *switch*, option hash can have following pairs:
390
390
 
391
391
  * **:default => value** - use default value of *value* if the option was not specified on the command argument list. The *value* will firstly be casted to string (with `#to_s`) and then it will be casted if casting is specified.
392
- * **:default_label => label** - display *label* in usage rather than default value - useful to descirbe default value if default value is generated if no value is provided
393
- * **:cast => cast specifier** - cast the provided value (or default) with given *cast specifier*.
394
- The specifier can be a class constant (like `Integer` or `Float`); the value will be provided to `#new` method of the class and resulting object used as option value. When provided constant does not respond to `#new` (i.e. it is a module) the `#load` method will be tried. If provided specifier is a Proc (or `lambda {}`) the Proc will be called with the value and resulting value will be used. Otherwise `CLI::ParsingError::CastError` will be raised.
392
+ * **:default_label => label** - display *label* in usage rather than default value - useful to describe default value if default value is generated if no value is provided
393
+ * **:cast => cast specifier** - cast the provided value (or default) with given *cast specifier*.
394
+ The specifier can be a class constant - the value will be provided to `#new` method of the class and resulting object used as option value. When provided constant does not respond to `#new` (i.e. it is a module) the `#load` method will be tried instead. If provided specifier is a Proc (or `lambda {}`) the Proc will be called with the value and resulting value will be used. Otherwise `CLI::ParsingError::CastError` will be raised. Special cast specified `Integer` or `Float` can also be used - the value will be strictly casted to integer or float type.
395
395
  * **:required => true** - if used and no *default* value is specified the `#parse` method will fail with `CLI::ParsingError::MissingOptionValueError` if the option was not specified in the command argument list. If `#parse!` method was used the program will exit with appropriate message.
396
396
 
397
397
  #### options :name [, options hash]
@@ -406,7 +406,7 @@ After the parser encounters command line argument that is not a *switch* or *opt
406
406
 
407
407
  Each argument will be matched to argument specifications in order and their value after optional casting will be available as `#parse` or `#parse!` returned object argument with the same name.
408
408
 
409
- Options hash can contain the same pairs as *option* expect of **:short => :symbol**.
409
+ Options hash can contain the same pairs as *option* expect of **:short => :symbol**.
410
410
 
411
411
  If defaults are used the parser will keep using default values until it has enough command line arguments available to fill all mandatory arguments.
412
412
  Arguments are required by default, use **:required => false** option pair to use `nil` value if argument is not specified on the command line argument list.
@@ -427,7 +427,7 @@ As with *switch* specifier the **:description => 'string'** can be used.
427
427
  Also **:cast => cast specifier** option pair can be used but the value will be an IO object and not string.
428
428
 
429
429
  ## Contributing to CLI
430
-
430
+
431
431
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
432
432
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
433
433
  * Fork the project
@@ -438,6 +438,5 @@ Also **:cast => cast specifier** option pair can be used but the value will be a
438
438
 
439
439
  ## Copyright
440
440
 
441
- Copyright (c) 2011 Jakub Pastuszek. See LICENSE.txt for
441
+ Copyright (c) 2011-2022 Jakub Pastuszek. See LICENSE.txt for
442
442
  further details.
443
-
data/Rakefile CHANGED
@@ -9,36 +9,9 @@ rescue Bundler::BundlerError => e
9
9
  $stderr.puts "Run `bundle install` to install missing gems"
10
10
  exit e.status_code
11
11
  end
12
- require 'rake'
13
12
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "cli"
18
- gem.homepage = "http://github.com/jpastuszek/cli"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Command line argument parser with stdin handling and usage generator}
21
- gem.description = %Q{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}
22
- gem.email = "jpastuszek@gmail.com"
23
- gem.authors = ["Jakub Pastuszek"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rspec/core'
29
13
  require 'rspec/core/rake_task'
30
- RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:rcov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
38
-
39
- require 'cucumber/rake/task'
40
- Cucumber::Rake::Task.new(:features)
41
-
14
+ RSpec::Core::RakeTask.new(:spec)
42
15
  task :default => :spec
43
16
 
44
17
  require 'rdoc/task'
data/cli.gemspec CHANGED
@@ -1,87 +1,17 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ Gem::Specification.new do |spec|
2
+ require 'bundler'
3
+ # spec is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
4
+ spec.name = "cli"
5
+ spec.version = "1.4.0"
6
+ spec.homepage = "http://github.com/jpastuszek/cli"
7
+ spec.license = "MIT"
8
+ spec.summary = %Q{Command line argument parser with stdin handling and usage generator}
9
+ spec.description = %Q{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}
10
+ spec.email = "jpastuszek@protonmail.com"
11
+ spec.authors = ["Jakub Pastuszek"]
5
12
 
6
- Gem::Specification.new do |s|
7
- s.name = "cli"
8
- s.version = "1.2.0"
13
+ spec.files = Dir['**/**'].grep_v(/.gem$/)
14
+ spec.require_paths = ["lib"]
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Jakub Pastuszek"]
12
- s.date = "2012-11-11"
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
- s.email = "jpastuszek@gmail.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.md",
26
- "Rakefile",
27
- "VERSION",
28
- "cli.gemspec",
29
- "examples/httpclient",
30
- "examples/ls",
31
- "examples/processor",
32
- "examples/sinatra",
33
- "features/cli.feature",
34
- "features/step_definitions/cli_steps.rb",
35
- "features/support/env.rb",
36
- "lib/cli.rb",
37
- "lib/cli/arguments.rb",
38
- "lib/cli/dsl.rb",
39
- "lib/cli/options.rb",
40
- "lib/cli/switches.rb",
41
- "spec/argument_spec.rb",
42
- "spec/cli_spec.rb",
43
- "spec/conflict_reporting_spec.rb",
44
- "spec/option_spec.rb",
45
- "spec/separator_spec.rb",
46
- "spec/spec_helper.rb",
47
- "spec/stdin_spec.rb",
48
- "spec/switch_spec.rb",
49
- "spec/usage_spec.rb"
50
- ]
51
- s.homepage = "http://github.com/jpastuszek/cli"
52
- s.licenses = ["MIT"]
53
- s.require_paths = ["lib"]
54
- s.rubygems_version = "1.8.15"
55
- s.summary = "Command line argument parser with stdin handling and usage generator"
56
-
57
- if s.respond_to? :specification_version then
58
- s.specification_version = 3
59
-
60
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
- s.add_development_dependency(%q<rspec>, ["~> 2.4"])
62
- s.add_development_dependency(%q<cucumber>, [">= 0"])
63
- s.add_development_dependency(%q<bundler>, ["~> 1.2"])
64
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
65
- s.add_development_dependency(%q<rcov>, [">= 0"])
66
- s.add_development_dependency(%q<rdoc>, ["~> 3.9"])
67
- s.add_development_dependency(%q<ruby-ip>, ["~> 0.9"])
68
- else
69
- s.add_dependency(%q<rspec>, ["~> 2.4"])
70
- s.add_dependency(%q<cucumber>, [">= 0"])
71
- s.add_dependency(%q<bundler>, ["~> 1.2"])
72
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
73
- s.add_dependency(%q<rcov>, [">= 0"])
74
- s.add_dependency(%q<rdoc>, ["~> 3.9"])
75
- s.add_dependency(%q<ruby-ip>, ["~> 0.9"])
76
- end
77
- else
78
- s.add_dependency(%q<rspec>, ["~> 2.4"])
79
- s.add_dependency(%q<cucumber>, [">= 0"])
80
- s.add_dependency(%q<bundler>, ["~> 1.2"])
81
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
82
- s.add_dependency(%q<rcov>, [">= 0"])
83
- s.add_dependency(%q<rdoc>, ["~> 3.9"])
84
- s.add_dependency(%q<ruby-ip>, ["~> 0.9"])
85
- end
16
+ Bundler.require(:default, :development)
86
17
  end
87
-
data/examples/httpclient CHANGED
@@ -3,22 +3,22 @@ require 'rubygems'
3
3
  require 'cli'
4
4
  require 'httpclient'
5
5
 
6
- options = CLI.new do
6
+ settings = CLI.new do
7
7
  option :server, :description => 'server address', :default => 'www.google.com'
8
8
  option :port, :description => 'server port', :cast => Integer, :default => 80
9
9
  argument :url, :description => 'URL to GET or POST to if arguments are given'
10
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 =~ /^\//
11
+ end.parse! do |settings|
12
+ fail "invalid URL '#{settings.url}', URL has to start with '/'" unless settings.url =~ /^\//
13
13
  end
14
14
 
15
15
  c = HTTPClient.new
16
16
 
17
17
  begin
18
- if options.post_arguments.empty?
19
- puts c.get_async("http://#{options.server}:#{options.port}#{options.url}").pop.content.read
18
+ if settings.post_arguments.empty?
19
+ puts c.get_async("http://#{settings.server}:#{settings.port}#{settings.url}").pop.content.read
20
20
  else
21
- puts c.post_async("http://#{options.server}:#{options.port}#{options.url}", options.post_arguments.join("\n")).pop.content.read
21
+ puts c.post_async("http://#{settings.server}:#{settings.port}#{settings.url}", settings.post_arguments.join("\n")).pop.content.read
22
22
  end
23
23
  rescue SocketError, Errno::ECONNREFUSED => e
24
24
  puts "Falied to connect: #{e}"
data/examples/ls CHANGED
@@ -3,20 +3,20 @@ require 'rubygems'
3
3
  require 'cli'
4
4
  require 'pathname'
5
5
 
6
- values = CLI.new do
6
+ settings = CLI.new do
7
7
  description 'Lists content of directories'
8
8
  switch :long, :short => :l, :description => 'use long listing'
9
9
  options :exclude, :short => :e, :description => 'exclude files from listing'
10
10
  arguments :directories, :cast => Pathname, :default => '.', :description => 'directories to list content of'
11
11
  end.parse!
12
12
 
13
- values.directories.each do |dir|
13
+ settings.directories.each do |dir|
14
14
  next unless dir.directory?
15
15
  dir.each_entry do |e|
16
16
  next if e.to_s == '.' or e.to_s == '..'
17
17
  e = dir + e
18
- next if values.exclude.include? e.to_s
19
- if values.long
18
+ next if settings.exclude.include? e.to_s
19
+ if settings.long
20
20
  puts "#{e.stat.uid}:#{e.stat.gid} #{e}"
21
21
  else
22
22
  puts e
data/examples/processor CHANGED
@@ -4,16 +4,16 @@ require 'cli'
4
4
  require 'pathname'
5
5
  require 'yaml'
6
6
 
7
- options = CLI.new do
7
+ settings = CLI.new do
8
8
  description 'Generate blog posts in given Jekyll directory from input statistics'
9
9
  stdin :log_data, :cast => YAML, :description => 'statistic data in YAML format'
10
10
  option :location, :short => :l, :description => 'location name (ex. Dublin, Singapore, Califorina)'
11
11
  option :csv_dir, :short => :c, :cast => Pathname, :default => 'csv', :description => 'directory name where CSV file will be storred (relative to jekyll-dir)'
12
12
  argument :jekyll_dir, :cast => Pathname, :default => '/var/lib/vhs/jekyll', :description => 'directory where site source is located'
13
- end.parse! do |options|
14
- fail 'jekyll-dir is not a directory' unless options.jekyll_dir.directory?
15
- fail '--csv-dir is not a directory (relative to jekyll-dir)' unless (options.jekyll_dir + options.csv_dir).directory?
13
+ end.parse! do |settings|
14
+ fail 'jekyll-dir is not a directory' unless settings.jekyll_dir.directory?
15
+ fail '--csv-dir is not a directory (relative to jekyll-dir)' unless (settings.jekyll_dir + settings.csv_dir).directory?
16
16
  end
17
17
 
18
- p options
18
+ p settings
19
19
 
data/examples/sinatra CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'cli'
4
4
  require 'ip'
5
5
 
6
- options = CLI.new do
6
+ settings = CLI.new do
7
7
  description 'Example CLI usage for Sinatra server application'
8
8
  version "1.0.0"
9
9
  switch :no_bind, :description => "Do not bind to TCP socket - useful with -s fastcgi option"
@@ -18,7 +18,7 @@ options = CLI.new do
18
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"
19
19
  end.parse!
20
20
 
21
- p options
21
+ p settings
22
22
 
23
23
  ## use to set sinatra settings
24
24
  #require 'sinatra/base'
@@ -26,13 +26,13 @@ p options
26
26
  #sinatra = Sinatra.new
27
27
  #
28
28
  #sinatra.set :environment, 'production'
29
- #sinatra.set :server, options.server
29
+ #sinatra.set :server, settings.server
30
30
  #sinatra.set :lock, true
31
31
  #sinatra.set :boundary, "thumnail image data"
32
- #sinatra.set :logging, (not options.no_logging)
33
- #sinatra.set :debug, options.debug
34
- #sinatra.set :optimization, (not options.no_optimization)
35
- #sinatra.set :limit_memory, options.limit_memory
36
- #sinatra.set :limit_map, options.limit_map
37
- #sinatra.set :limit_disk, options.limit_disk
32
+ #sinatra.set :logging, (not settings.no_logging)
33
+ #sinatra.set :debug, settings.debug
34
+ #sinatra.set :optimization, (not settings.no_optimization)
35
+ #sinatra.set :limit_memory, settings.limit_memory
36
+ #sinatra.set :limit_map, settings.limit_map
37
+ #sinatra.set :limit_disk, settings.limit_disk
38
38
 
data/lib/cli/dsl.rb CHANGED
@@ -19,9 +19,9 @@ class CLI
19
19
 
20
20
  if cast_to.is_a? Module # all classes are modules
21
21
  if cast_to == Integer
22
- value.to_i
22
+ Integer(value)
23
23
  elsif cast_to == Float
24
- value.to_f
24
+ Float(value)
25
25
  elsif cast_to.respond_to? :new
26
26
  cast_to.new(value)
27
27
  elsif cast_to.respond_to? :load
@@ -37,7 +37,7 @@ class CLI
37
37
  end
38
38
  end
39
39
  rescue => e
40
- raise ParsingError::CastError.new(@name, @options[:cast].name, e)
40
+ raise ParsingError::CastError.new(@name, @options[:cast].respond_to?(:name) ? @options[:cast].name : @options[:cast], e)
41
41
  end
42
42
  end
43
43
  end