cowtech-lib 1.9.5.1 → 1.9.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/cowtech-lib.gemspec +2 -2
- data/lib/cowtech-lib/console.rb +3 -3
- data/lib/cowtech-lib/option_parser.rb +12 -12
- data/lib/cowtech-lib/script.rb +2 -2
- data/lib/cowtech-lib/shell.rb +5 -5
- data/lib/cowtech-lib/version.rb +2 -2
- metadata +4 -4
data/cowtech-lib.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cowtech-lib}
|
8
|
-
s.version = "1.9.
|
8
|
+
s.version = "1.9.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Shogun}]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-13}
|
13
13
|
s.description = %q{A general purpose utility library.}
|
14
14
|
s.email = %q{shogun_panda@me.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/cowtech-lib/console.rb
CHANGED
@@ -176,7 +176,7 @@ module Cowtech
|
|
176
176
|
end
|
177
177
|
|
178
178
|
# Parse the message
|
179
|
-
|
179
|
+
if !args[:plain] then
|
180
180
|
begin
|
181
181
|
xml = "<text>#{msg}</text>"
|
182
182
|
msg = self.parse_message(REXML::Document.new(xml).root)
|
@@ -286,11 +286,11 @@ module Cowtech
|
|
286
286
|
def read(args)
|
287
287
|
# Adjust prompt
|
288
288
|
msg = args[:msg] + ((msg !~ /([:?](\s*))$/) ? ":" : "")
|
289
|
-
msg += " "
|
289
|
+
msg += " " if msg !~ / ^/
|
290
290
|
|
291
291
|
# Turn choices into regular expressions
|
292
292
|
regexps = (args[:valids] || []).force_array.collect do |valid|
|
293
|
-
|
293
|
+
if !valid.is_a?(Regexp) then
|
294
294
|
valid = Regexp.new((valid !~ /^\^/ ? "^" : "") + valid + (valid !~ /\$$/ ? "$" : ""), Regexp::EXTENDED + (args[:case_sensitive] ? Regexp::IGNORECASE : 0), "U")
|
295
295
|
else
|
296
296
|
valid
|
@@ -66,10 +66,10 @@ module Cowtech
|
|
66
66
|
# * <em>:required</em>: Whether the option is required
|
67
67
|
# * <em>:priority</em>: Priority for the option. Used only on the help message to sort (by increasing priority) the options.
|
68
68
|
def <<(options)
|
69
|
-
options = [options]
|
69
|
+
options = [options] if !options.is_a?(Array)
|
70
70
|
|
71
71
|
options.each do |option|
|
72
|
-
@console.fatal(:msg => "Every attribute must be an Hash.", :dots => false)
|
72
|
+
@console.fatal(:msg => "Every attribute must be an Hash.", :dots => false) if !option.is_a?(Hash)
|
73
73
|
|
74
74
|
# Use symbols for names
|
75
75
|
option[:name] = option[:name].to_sym
|
@@ -78,26 +78,26 @@ module Cowtech
|
|
78
78
|
option[:type] ||= :string
|
79
79
|
|
80
80
|
# Check if type is valid
|
81
|
-
@console.fatal(:msg => "Invalid option type #{option[:type]} for option #{option[:name]}. Valid type are the following:\n\t#{@@valid_types.keys.join(", ")}.", :dots => false)
|
81
|
+
@console.fatal(:msg => "Invalid option type #{option[:type]} for option #{option[:name]}. Valid type are the following:\n\t#{@@valid_types.keys.join(", ")}.", :dots => false) if !@@valid_types.keys.include?(option[:type])
|
82
82
|
|
83
83
|
# Adjust the default value
|
84
84
|
case option[:type]
|
85
85
|
when :bool then
|
86
|
-
option[:default] = false
|
86
|
+
option[:default] = false if !option[:default] == true
|
87
87
|
when :action then
|
88
88
|
option[:required] = false
|
89
89
|
else
|
90
|
-
option[:default] = @@valid_types[option[:type]][1]
|
90
|
+
option[:default] = @@valid_types[option[:type]][1] if ! (option[:default].is_a?(@@valid_types[option[:type]][0]) == true && option[:default] != nil)
|
91
91
|
end
|
92
92
|
|
93
93
|
# Adjust priority
|
94
|
-
option[:priority] = option[:priority].to_s.to_i
|
94
|
+
option[:priority] = option[:priority].to_s.to_i if !option[:priority].is_a?(Integer)
|
95
95
|
|
96
96
|
# Prepend dashes
|
97
|
-
option[:short] = "-" + option[:short]
|
97
|
+
option[:short] = "-" + option[:short] if !option[:short] =~ /^-/
|
98
98
|
while not option[:long] =~ /^--/ do option[:long] = "-" + option[:long] end
|
99
|
-
@console.fatal(:msg => "Invalid short form \"#{option[:short]}\".", :dots => false)
|
100
|
-
@console.fatal(:msg => "Invalid long form \"#{option[:long]}\".", :dots => false)
|
99
|
+
@console.fatal(:msg => "Invalid short form \"#{option[:short]}\".", :dots => false) if !option[:short] =~ /^-[0-9a-z]$/i
|
100
|
+
@console.fatal(:msg => "Invalid long form \"#{option[:long]}\".", :dots => false) if !option[:long] =~ /^--([0-9a-z-]+)$/i
|
101
101
|
|
102
102
|
# Check for choices if the type is choices
|
103
103
|
if option[:type] == :choice then
|
@@ -170,7 +170,7 @@ module Cowtech
|
|
170
170
|
given = $1
|
171
171
|
|
172
172
|
if exception.is_a?(GetoptLong::InvalidOption) then
|
173
|
-
@console.fatal(:msg => "Unknown option \"#{given}\".", :dots => false)
|
173
|
+
@console.fatal(:msg => "Unknown option \"#{given}\".", :dots => false) if !args[:ignore_unknown]
|
174
174
|
elsif exception.is_a?(GetoptLong::MissingArgument) then
|
175
175
|
@console.fatal(:msg => "Option \"-#{given}\" requires an argument.", :dots => false)
|
176
176
|
end
|
@@ -240,7 +240,7 @@ module Cowtech
|
|
240
240
|
# * <em>options</em>: Options list
|
241
241
|
# Returns: If a single argument is provided, only a value is returned, else an hash (name => value). If no argument is provided, return every option
|
242
242
|
def [](*options)
|
243
|
-
options = [options]
|
243
|
+
options = [options] if !options.is_a?(Array)
|
244
244
|
options = @options.keys if options.length == 0
|
245
245
|
|
246
246
|
if options.length == 1 then
|
@@ -289,7 +289,7 @@ module Cowtech
|
|
289
289
|
opt = @options[key]
|
290
290
|
|
291
291
|
popt = "#{[opt[:short], opt[:long]].join(", ")}"
|
292
|
-
popt += ("=" + (if opt[:meta] then opt[:meta] else "ARG" end))
|
292
|
+
popt += ("=" + (if opt[:meta] then opt[:meta] else "ARG" end)) if ![:bool, :action].include?(opt[:type])
|
293
293
|
popts[key] = popt
|
294
294
|
maxlen = popt.length if popt.length > maxlen
|
295
295
|
end
|
data/lib/cowtech-lib/script.rb
CHANGED
@@ -88,8 +88,8 @@ module Cowtech
|
|
88
88
|
|
89
89
|
# Run the block
|
90
90
|
rv = yield
|
91
|
-
rv = :ok
|
92
|
-
rv = [rv, true]
|
91
|
+
rv = :ok if !rv.is_a?(Symbol)
|
92
|
+
rv = [rv, true] if !rv.is_a?(Array)
|
93
93
|
|
94
94
|
# Show the result
|
95
95
|
if args.fetch(:show_result, true) then
|
data/lib/cowtech-lib/shell.rb
CHANGED
@@ -55,7 +55,7 @@ module Cowtech
|
|
55
55
|
@console.status(:ok)
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
if !@console.skip_commands == true then
|
59
59
|
rv[:status] = Open4::open4(command + " 2>&1") { |pid, stdin, stdout, stderr|
|
60
60
|
stdout.each_line do |line|
|
61
61
|
rv[:output] << line
|
@@ -207,7 +207,7 @@ module Cowtech
|
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
-
break
|
210
|
+
break if !rv
|
211
211
|
end
|
212
212
|
|
213
213
|
rv ? rv : @console.status(:fail, :fatal => args[:fatal])
|
@@ -261,16 +261,16 @@ module Cowtech
|
|
261
261
|
rv = false
|
262
262
|
end
|
263
263
|
|
264
|
-
break
|
264
|
+
break if !rv
|
265
265
|
end
|
266
266
|
else # If we are copying or moving to a file
|
267
|
-
|
267
|
+
if !files.kind_of?(String) == true and dest.kind_of?(String) == true then
|
268
268
|
@console.error("Cowtech::Lib::Shell#copy: To copy a single file, both files and dest arguments must be a string.", :dots => false, :fatal => args[:fatal])
|
269
269
|
rv = false
|
270
270
|
else
|
271
271
|
dst_dir = File.dirname(dest)
|
272
272
|
|
273
|
-
|
273
|
+
if !self.file_check?(:file => dst_dir, :tests => [:exists, :directory]) then
|
274
274
|
self.create_directories(:files => dst_dir, :mode => 0755, :fatal => args[:fatal], :show_errors => args[:show_errors])
|
275
275
|
end
|
276
276
|
|
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.6.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: 2011-07-
|
12
|
+
date: 2011-07-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: open4
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152805660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152805660
|
25
25
|
description: A general purpose utility library.
|
26
26
|
email: shogun_panda@me.com
|
27
27
|
executables: []
|