cli 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,26 +15,26 @@ 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
37
+ puts c.post_async("http://#{settings.server}:#{settings.port}#{settings.url}", settings.post_arguments.join("\n")).pop.content.read
38
38
  end
39
39
  rescue SocketError, Errno::ECONNREFUSED => e
40
40
  puts "Falied to connect: #{e}"
@@ -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
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
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
173
  option :location, :short => :l, :description => 'location name (ex. Dublin, Singapore, Califorina)'
174
174
  option :csv_dir, :short => :c, :cast => Pathname, :default => 'csv', :description => 'directory name where CSV file will be storred (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
  ```
@@ -205,7 +205,7 @@ With this example usage (assuming /var/lib/vhs/jekyll/csv dir exist):
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
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.3.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cli"
8
- s.version = "1.3.0"
8
+ s.version = "1.3.1"
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 = "2012-11-11"
12
+ s.date = "2012-11-16"
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 = [
@@ -51,7 +51,7 @@ Gem::Specification.new do |s|
51
51
  s.homepage = "http://github.com/jpastuszek/cli"
52
52
  s.licenses = ["MIT"]
53
53
  s.require_paths = ["lib"]
54
- s.rubygems_version = "1.8.15"
54
+ s.rubygems_version = "1.8.24"
55
55
  s.summary = "Command line argument parser with stdin handling and usage generator"
56
56
 
57
57
  if s.respond_to? :specification_version then
@@ -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}"
@@ -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
@@ -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
 
@@ -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
 
@@ -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
@@ -48,6 +48,14 @@ describe CLI do
48
48
  }.should raise_error(CLI::ParsingError::CastError)
49
49
  end
50
50
 
51
+ it "casting should fail if there is error in cast lambda" do
52
+ lambda {
53
+ ps = CLI.new do
54
+ argument :size, :cast => lambda{|v| fail 'test'}
55
+ end.parse(['24.99x'])
56
+ }.should raise_error(CLI::ParsingError::CastError)
57
+ end
58
+
51
59
  it "should cast default value" do
52
60
  ps = CLI.new do
53
61
  argument :number, :cast => Integer, :default => '123'
@@ -42,6 +42,14 @@ describe CLI do
42
42
  }.should raise_error(CLI::ParsingError::CastError)
43
43
  end
44
44
 
45
+ it "casting should fail if there is error in cast lambda" do
46
+ lambda {
47
+ ps = CLI.new do
48
+ option :size, :cast => lambda{|v| fail 'test'}
49
+ end.parse(['--size', '24.99x'])
50
+ }.should raise_error(CLI::ParsingError::CastError)
51
+ end
52
+
45
53
  it "should support casting of multiple options" do
46
54
  ps = CLI.new do
47
55
  options :size, :cast => Integer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-11 00:00:00.000000000 Z
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70249594753380 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '2.4'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70249594753380
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.4'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: cucumber
27
- requirement: &70249594752900 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70249594752900
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: bundler
38
- requirement: &70249594752320 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '1.2'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70249594752320
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: jeweler
49
- requirement: &70249594751660 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 1.6.4
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70249594751660
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.6.4
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rcov
60
- requirement: &70249594751120 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70249594751120
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: rdoc
71
- requirement: &70249594750500 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '3.9'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70249594750500
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '3.9'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: ruby-ip
82
- requirement: &70249594750020 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ~>
@@ -87,7 +117,12 @@ dependencies:
87
117
  version: '0.9'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70249594750020
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0.9'
91
126
  description: Command Line Interface gem allows you to quickly specify command argument
92
127
  parser that will automatically generate usage, handle stdin, switches, options and
93
128
  arguments with default values and value casting
@@ -143,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
178
  version: '0'
144
179
  segments:
145
180
  - 0
146
- hash: 2443358638840763179
181
+ hash: 4581396442984806674
147
182
  required_rubygems_version: !ruby/object:Gem::Requirement
148
183
  none: false
149
184
  requirements:
@@ -152,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
187
  version: '0'
153
188
  requirements: []
154
189
  rubyforge_project:
155
- rubygems_version: 1.8.15
190
+ rubygems_version: 1.8.24
156
191
  signing_key:
157
192
  specification_version: 3
158
193
  summary: Command line argument parser with stdin handling and usage generator