cowtech-lib 1.9.7.0 → 1.9.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/cowtech-lib.gemspec +2 -2
- data/lib/cowtech-lib/option_parser.rb +29 -14
- data/lib/cowtech-lib/shell.rb +4 -4
- data/lib/cowtech-lib/version.rb +1 -1
- metadata +6 -6
data/cowtech-lib.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "cowtech-lib"
|
8
|
-
s.version = "1.9.
|
8
|
+
s.version = "1.9.8.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Shogun"]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-11"
|
13
13
|
s.description = "A general purpose utility library."
|
14
14
|
s.email = "shogun_panda@me.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -104,7 +104,7 @@ module Cowtech
|
|
104
104
|
if option[:choices] == nil then
|
105
105
|
@console.fatal(:msg => "Option \"#{option[:name]}\" of type choice requires a valid choices list (every element should be a regular expression).")
|
106
106
|
else
|
107
|
-
option[:choices].collect!
|
107
|
+
option[:choices].collect! { |choice| Regexp.new(choice) }
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -134,7 +134,7 @@ module Cowtech
|
|
134
134
|
args ||= {}
|
135
135
|
# Create options
|
136
136
|
noat = [:bool, :action]
|
137
|
-
sopts = @options.each_value.collect
|
137
|
+
sopts = @options.each_value.collect { |option| [option[:long], option[:short], noat.include?(option[:type]) ? GetoptLong::NO_ARGUMENT : GetoptLong::REQUIRED_ARGUMENT] }
|
138
138
|
|
139
139
|
opts = GetoptLong.new(*sopts)
|
140
140
|
opts.quiet = true
|
@@ -146,17 +146,28 @@ module Cowtech
|
|
146
146
|
option = @options[optname]
|
147
147
|
value = nil
|
148
148
|
|
149
|
-
|
150
149
|
# VALIDATE ARGUMENT DUE TO CASE
|
151
150
|
case option[:type]
|
152
151
|
when :string then
|
153
152
|
value = arg
|
154
153
|
when :int then
|
155
|
-
if arg.strip =~ /^(-?)(\d+)$/ then
|
154
|
+
if arg.strip =~ /^(-?)(\d+)$/ then
|
155
|
+
value = arg.to_i(10)
|
156
|
+
else
|
157
|
+
@console.fatal(:msg => "Argument of option \"#{given}\" must be an integer.", :dots => false)
|
158
|
+
end
|
156
159
|
when :float then
|
157
|
-
if arg.strip =~ /^(-?)(\d*)(\.(\d+))?$/ && arg.strip() != "." then
|
160
|
+
if arg.strip =~ /^(-?)(\d*)(\.(\d+))?$/ && arg.strip() != "." then
|
161
|
+
value = arg.to_f
|
162
|
+
else
|
163
|
+
@console.fatal(:msg => "Argument of option \"#{given}\" must be a float.", :dots => false)
|
164
|
+
end
|
158
165
|
when :choice then
|
159
|
-
if @options[optname].choices.find_index { |choice| arg =~ choice } then
|
166
|
+
if @options[optname].choices.find_index { |choice| arg =~ choice } then
|
167
|
+
value = arg
|
168
|
+
else
|
169
|
+
@console.fatal(:msg => "Invalid argument (invalid choice) for option \"#{given}\".", :dots => false)
|
170
|
+
end
|
160
171
|
when :list then
|
161
172
|
value = arg.split(",")
|
162
173
|
else
|
@@ -264,17 +275,17 @@ module Cowtech
|
|
264
275
|
# Print app name
|
265
276
|
if @app_name then
|
266
277
|
print "#{@app_name}"
|
267
|
-
|
268
|
-
|
278
|
+
print " #{@app_version}" if @app_version > 0
|
279
|
+
print " - #{@description}" if @description
|
269
280
|
print "\n"
|
270
281
|
end
|
271
282
|
|
272
283
|
# Print usage
|
273
|
-
|
274
|
-
print "#{
|
284
|
+
print "#{@messages["pre_usage"]}\n" if @messages["pre_usage"]
|
285
|
+
print "#{@usage ? @usage : "Usage: #{ARGV[0]} [OPTIONS]"}\n"
|
275
286
|
|
276
287
|
# Print pre_options
|
277
|
-
|
288
|
+
print "#{@messages["pre_options"]}\n" if @messages["pre_options"]
|
278
289
|
print "\nValid options are:\n"
|
279
290
|
|
280
291
|
# Order options for printing
|
@@ -289,7 +300,7 @@ module Cowtech
|
|
289
300
|
opt = @options[key]
|
290
301
|
|
291
302
|
popt = "#{[opt[:short], opt[:long]].join(", ")}"
|
292
|
-
popt += ("=" + (
|
303
|
+
popt += ("=" + (opt[:meta] ? opt[:meta] : "ARG")) if ![:bool, :action].include?(opt[:type])
|
293
304
|
popts[key] = popt
|
294
305
|
maxlen = popt.length if popt.length > maxlen
|
295
306
|
end
|
@@ -301,7 +312,7 @@ module Cowtech
|
|
301
312
|
end
|
302
313
|
|
303
314
|
# Print post_options
|
304
|
-
|
315
|
+
print "#{@messages["post_options"]}\n" if @messages["post_options"] then
|
305
316
|
end
|
306
317
|
|
307
318
|
#Creates a new OptionParser.
|
@@ -327,7 +338,11 @@ module Cowtech
|
|
327
338
|
|
328
339
|
# Copy messages
|
329
340
|
messages = args[:messages] || {}
|
330
|
-
if messages.is_a?(Hash) then
|
341
|
+
if messages.is_a?(Hash) then
|
342
|
+
@messages = messages
|
343
|
+
else
|
344
|
+
@console.fatal(:msg => "CowtechLib::OptionParser::initialize msgs argument must be an hash.")
|
345
|
+
end
|
331
346
|
|
332
347
|
# Initialize variables
|
333
348
|
@console = Console.new
|
data/lib/cowtech-lib/shell.rb
CHANGED
@@ -243,13 +243,13 @@ module Cowtech
|
|
243
243
|
end
|
244
244
|
rescue StandardError => e
|
245
245
|
if args[:show_errors] && e.message =~ /^Permission denied - (.+)/ then
|
246
|
-
self.error("Cannot #{
|
246
|
+
self.error("Cannot #{must_move ? "move" : "copy"} entry <text style=\"bold white\">#{file}</text> to non-writable entry <text style=\"bold white\">#{dest}</text>", false, false, false) if m != nil
|
247
247
|
end
|
248
248
|
|
249
249
|
rv = false
|
250
250
|
rescue Exception => e
|
251
251
|
if args[:show_errors] then
|
252
|
-
@console.error("Cannot #{
|
252
|
+
@console.error("Cannot #{move ? "move" : "copy"} following entries to <text style=\"bold white\">#{dest}</text>:", :dots => false)
|
253
253
|
@console.indent_region(3) do
|
254
254
|
files.each do |afile|
|
255
255
|
@console.write(:msg => afile, :dots => false)
|
@@ -283,10 +283,10 @@ module Cowtech
|
|
283
283
|
FileUtils.cp(files, dest, {:noop => @console.skip_commands, :verbose => @console.skip_commands})
|
284
284
|
end
|
285
285
|
rescue StandardError => e
|
286
|
-
@console.error("Cannot #{
|
286
|
+
@console.error("Cannot #{move ? "move" : "copy"} entry <text style=\"bold white\">#{files}</text> to non-writable entry<text style=\"bold white\"> #{dest}</text>", :dots => false, :fatal => args[:fatal]) if args[:show_errors] && (e.message =~ /^Permission denied - (.+)/)
|
287
287
|
rv = false
|
288
288
|
rescue Exception => e
|
289
|
-
@console.error("Cannot #{
|
289
|
+
@console.error("Cannot #{move ? "move" : "copy"} <text style=\"bold white\">#{files}</text> to <text style=\"bold_white\">#{dest}</text> due to an error: <text style=\"bold red\">#{e}</text>", :dots => false, :fatal => args[:fatal]) if args[:show_errors]
|
290
290
|
rv = false
|
291
291
|
end
|
292
292
|
end
|
data/lib/cowtech-lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cowtech-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.8.0
|
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-01-
|
12
|
+
date: 2012-01-11 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jeweler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70357825387040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70357825387040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: open4
|
27
|
-
requirement: &
|
27
|
+
requirement: &70357825386560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70357825386560
|
36
36
|
description: A general purpose utility library.
|
37
37
|
email: shogun_panda@me.com
|
38
38
|
executables: []
|