cli 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -7
- data/Gemfile.lock +29 -37
- data/README.md +43 -44
- data/Rakefile +1 -28
- data/cli.gemspec +14 -84
- data/examples/httpclient +6 -6
- data/examples/ls +4 -4
- data/examples/processor +5 -5
- data/examples/sinatra +9 -9
- data/lib/cli/dsl.rb +3 -3
- data/rdoc/CLI/Arguments.html +178 -0
- data/rdoc/CLI/DSL/Argument.html +200 -0
- data/rdoc/CLI/DSL/Arguments.html +172 -0
- data/rdoc/CLI/DSL/Base.html +154 -0
- data/rdoc/CLI/DSL/Cast.html +152 -0
- data/rdoc/CLI/DSL/Description.html +150 -0
- data/rdoc/CLI/DSL/Input.html +143 -0
- data/rdoc/CLI/DSL/MultiDefault.html +151 -0
- data/rdoc/CLI/DSL/Option.html +143 -0
- data/rdoc/CLI/DSL/Options.html +142 -0
- data/rdoc/CLI/DSL/Switch.html +267 -0
- data/rdoc/CLI/DSL/Value.html +238 -0
- data/rdoc/CLI/DSL.html +91 -0
- data/rdoc/CLI/Options.html +200 -0
- data/rdoc/CLI/ParserError/ArgumentNameSpecifiedTwice.html +138 -0
- data/rdoc/CLI/ParserError/LongNameSpecifiedTwiceError.html +138 -0
- data/rdoc/CLI/ParserError/MultipleArgumentsSpecifierError.html +138 -0
- data/rdoc/CLI/ParserError/NameArgumetNotSymbolError.html +138 -0
- data/rdoc/CLI/ParserError/OptionsArgumentNotHashError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameIsInvalidError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameNotSymbolError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameSpecifiedTwiceError.html +138 -0
- data/rdoc/CLI/ParserError.html +97 -0
- data/rdoc/CLI/ParsingError/CastError.html +138 -0
- data/rdoc/CLI/ParsingError/MandatoryArgumentNotSpecifiedError.html +138 -0
- data/rdoc/CLI/ParsingError/MandatoryOptionsNotSpecifiedError.html +138 -0
- data/rdoc/CLI/ParsingError/MissingOptionValueError.html +138 -0
- data/rdoc/CLI/ParsingError/UnknownSwitchError.html +138 -0
- data/rdoc/CLI/ParsingError/UsageError.html +97 -0
- data/rdoc/CLI/ParsingError.html +97 -0
- data/rdoc/CLI/Switches.html +306 -0
- data/rdoc/CLI/Values.html +202 -0
- data/rdoc/CLI.html +652 -0
- data/rdoc/README_md.html +553 -0
- data/rdoc/created.rid +7 -0
- data/rdoc/css/fonts.css +167 -0
- data/rdoc/css/rdoc.css +639 -0
- data/rdoc/fonts/Lato-Light.ttf +0 -0
- data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
- data/rdoc/fonts/Lato-Regular.ttf +0 -0
- data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/rdoc/images/add.png +0 -0
- data/rdoc/images/arrow_up.png +0 -0
- data/rdoc/images/brick.png +0 -0
- data/rdoc/images/brick_link.png +0 -0
- data/rdoc/images/bug.png +0 -0
- data/rdoc/images/bullet_black.png +0 -0
- data/rdoc/images/bullet_toggle_minus.png +0 -0
- data/rdoc/images/bullet_toggle_plus.png +0 -0
- data/rdoc/images/date.png +0 -0
- data/rdoc/images/delete.png +0 -0
- data/rdoc/images/find.png +0 -0
- data/rdoc/images/loadingAnimation.gif +0 -0
- data/rdoc/images/macFFBgHack.png +0 -0
- data/rdoc/images/package.png +0 -0
- data/rdoc/images/page_green.png +0 -0
- data/rdoc/images/page_white_text.png +0 -0
- data/rdoc/images/page_white_width.png +0 -0
- data/rdoc/images/plugin.png +0 -0
- data/rdoc/images/ruby.png +0 -0
- data/rdoc/images/tag_blue.png +0 -0
- data/rdoc/images/tag_green.png +0 -0
- data/rdoc/images/transparent.png +0 -0
- data/rdoc/images/wrench.png +0 -0
- data/rdoc/images/wrench_orange.png +0 -0
- data/rdoc/images/zoom.png +0 -0
- data/rdoc/index.html +120 -0
- data/rdoc/js/darkfish.js +84 -0
- data/rdoc/js/navigation.js +105 -0
- data/rdoc/js/navigation.js.gz +0 -0
- data/rdoc/js/search.js +110 -0
- data/rdoc/js/search_index.js +1 -0
- data/rdoc/js/search_index.js.gz +0 -0
- data/rdoc/js/searcher.js +229 -0
- data/rdoc/js/searcher.js.gz +0 -0
- data/rdoc/table_of_contents.html +533 -0
- data/spec/argument_spec.rb +122 -99
- data/spec/cli_spec.rb +27 -28
- data/spec/conflict_reporting_spec.rb +16 -17
- data/spec/option_spec.rb +79 -56
- data/spec/separator_spec.rb +19 -20
- data/spec/stdin_spec.rb +13 -14
- data/spec/switch_spec.rb +15 -16
- data/spec/usage_spec.rb +80 -81
- metadata +91 -104
- data/.document +0 -5
- data/.rspec +0 -1
- data/VERSION +0 -1
- data/features/cli.feature +0 -9
- data/features/step_definitions/cli_steps.rb +0 -0
- 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 "
|
7
|
-
gem "
|
8
|
-
gem "bundler", "~>
|
9
|
-
gem "
|
10
|
-
gem "
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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 (~>
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
18
|
+
require 'rubygems'
|
19
19
|
require 'cli'
|
20
20
|
require 'httpclient'
|
21
21
|
|
22
|
-
|
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 |
|
28
|
-
fail "invalid 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
|
35
|
-
puts c.get_async("http://#{
|
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://#{
|
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 "
|
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
|
-
|
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,
|
116
|
+
sinatra.set :server, settings.server
|
117
117
|
sinatra.set :lock, true
|
118
|
-
sinatra.set :boundary, "
|
119
|
-
sinatra.set :logging, (not
|
120
|
-
sinatra.set :debug,
|
121
|
-
sinatra.set :optimization, (not
|
122
|
-
sinatra.set :limit_memory,
|
123
|
-
sinatra.set :limit_map,
|
124
|
-
sinatra.set :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
|
-
|
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,
|
174
|
-
option :csv_dir, :short => :c, :cast => Pathname, :default => 'csv', :description => 'directory name where CSV file will be
|
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 |
|
177
|
-
fail 'jekyll-dir is not a directory' unless
|
178
|
-
fail '--csv-dir is not a directory (relative to jekyll-dir)' unless (
|
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
|
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,
|
196
|
-
--csv-dir (-c) [csv] - directory name where CSV file will be
|
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 `
|
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
|
-
|
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
|
-
|
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
|
254
|
-
if
|
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
|
393
|
-
* **:cast => cast specifier** - cast the provided value (or default) with given *cast specifier*.
|
394
|
-
The specifier can be a class constant
|
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)
|
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
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
s.version = "1.2.0"
|
13
|
+
spec.files = Dir['**/**'].grep_v(/.gem$/)
|
14
|
+
spec.require_paths = ["lib"]
|
9
15
|
|
10
|
-
|
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
|
-
|
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 |
|
12
|
-
fail "invalid 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
|
19
|
-
puts c.get_async("http://#{
|
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://#{
|
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
|
-
|
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
|
-
|
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
|
19
|
-
if
|
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
|
-
|
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 |
|
14
|
-
fail 'jekyll-dir is not a directory' unless
|
15
|
-
fail '--csv-dir is not a directory (relative to jekyll-dir)' unless (
|
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
|
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
|
-
|
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
|
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,
|
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
|
33
|
-
#sinatra.set :debug,
|
34
|
-
#sinatra.set :optimization, (not
|
35
|
-
#sinatra.set :limit_memory,
|
36
|
-
#sinatra.set :limit_map,
|
37
|
-
#sinatra.set :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
|
22
|
+
Integer(value)
|
23
23
|
elsif cast_to == Float
|
24
|
-
value
|
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
|