cowtech-lib 1.9.6.0 → 1.9.6.1
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/console.rb +1 -1
- data/lib/cowtech-lib/option_parser.rb +9 -9
- data/lib/cowtech-lib/shell.rb +6 -6
- data/lib/cowtech-lib/version.rb +1 -1
- 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.6.
|
8
|
+
s.version = "1.9.6.1"
|
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-14}
|
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
@@ -107,7 +107,7 @@ module Cowtech
|
|
107
107
|
# Returns: The new text
|
108
108
|
def parse_message(node, stack = [])
|
109
109
|
rv = ""
|
110
|
-
styles = (node.name == "text"
|
110
|
+
styles = (node.name == "text" && node.attributes["style"]) ? node.attributes["style"].split(" ") : nil
|
111
111
|
|
112
112
|
# Add style of current tag
|
113
113
|
if styles then
|
@@ -83,11 +83,11 @@ module Cowtech
|
|
83
83
|
# Adjust the default value
|
84
84
|
case option[:type]
|
85
85
|
when :bool then
|
86
|
-
option[:default] = false if
|
86
|
+
option[:default] = false if option[:default] == false
|
87
87
|
when :action then
|
88
88
|
option[:required] = false
|
89
89
|
else
|
90
|
-
option[:default] = @@valid_types[option[:type]][1] if
|
90
|
+
option[:default] = @@valid_types[option[:type]][1] if option[:default].is_a?(@@valid_types[option[:type]][0]) && option[:default] != nil
|
91
91
|
end
|
92
92
|
|
93
93
|
# Adjust priority
|
@@ -95,9 +95,9 @@ module Cowtech
|
|
95
95
|
|
96
96
|
# Prepend dashes
|
97
97
|
option[:short] = "-" + option[:short] if !option[:short] =~ /^-/
|
98
|
-
while
|
99
|
-
@console.fatal(:msg => "Invalid short form \"#{option[:short]}\".", :dots => false) if
|
100
|
-
@console.fatal(:msg => "Invalid long form \"#{option[:long]}\".", :dots => false) if
|
98
|
+
while option[:long] !~ /^--/ do option[:long] = "-" + option[:long] end
|
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
|
@@ -154,7 +154,7 @@ module Cowtech
|
|
154
154
|
when :int then
|
155
155
|
if arg.strip =~ /^(-?)(\d+)$/ then value = arg.to_i(10) else @console.fatal(:msg => "Argument of option \"#{given}\" must be an integer.", :dots => false) end
|
156
156
|
when :float then
|
157
|
-
if arg.strip =~ /^(-?)(\d*)(\.(\d+))?$/
|
157
|
+
if arg.strip =~ /^(-?)(\d*)(\.(\d+))?$/ && arg.strip() != "." then value = arg.to_f else @console.fatal(:msg => "Argument of option \"#{given}\" must be a float.", :dots => false) end
|
158
158
|
when :choice then
|
159
159
|
if @options[optname].choices.find_index { |choice| arg =~ choice } then value = arg else @console.fatal(:msg => "Invalid argument (invalid choice) for option \"#{given}\".", :dots => false) end
|
160
160
|
when :list then
|
@@ -183,7 +183,7 @@ module Cowtech
|
|
183
183
|
@args = ARGV
|
184
184
|
|
185
185
|
# CHECK IF HELP WAS REQUESTED
|
186
|
-
if self.provided?("help")
|
186
|
+
if self.provided?("help") && !args[:ignore_help] then
|
187
187
|
self.print_help
|
188
188
|
exit(0)
|
189
189
|
end
|
@@ -192,9 +192,9 @@ module Cowtech
|
|
192
192
|
@inserted[:name].each do |key|
|
193
193
|
option = @options[key]
|
194
194
|
|
195
|
-
if option[:required] == true
|
195
|
+
if option[:required] == true && option[:value] == nil then
|
196
196
|
@console.fatal(:msg => "Required option \"#{option[:name]}\" not specified.", :dots => false)
|
197
|
-
elsif option[:value] == true
|
197
|
+
elsif option[:value] == true && option[:type] == :action then
|
198
198
|
option.action.call
|
199
199
|
end
|
200
200
|
end
|
data/lib/cowtech-lib/shell.rb
CHANGED
@@ -55,7 +55,7 @@ module Cowtech
|
|
55
55
|
@console.status(:ok)
|
56
56
|
end
|
57
57
|
|
58
|
-
if !@console.skip_commands
|
58
|
+
if !@console.skip_commands 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
|
@@ -66,7 +66,7 @@ module Cowtech
|
|
66
66
|
rv[:output] = rv[:output].join("\n")
|
67
67
|
|
68
68
|
@console.status(:status => rv[:status] == 0 ? :ok : :fail, :fatal => false) if args[:show_exit]
|
69
|
-
exit(1) if args[:fatal]
|
69
|
+
exit(1) if args[:fatal] && rv[:status] != 0
|
70
70
|
rv
|
71
71
|
end
|
72
72
|
|
@@ -232,7 +232,7 @@ module Cowtech
|
|
232
232
|
# If we are copy or moving to a directory
|
233
233
|
if args[:destination_is_directory] then
|
234
234
|
files = (args[:files] || []).force_array
|
235
|
-
dest += "/" if self.file_check?(:file => dest, :tests => :directory)
|
235
|
+
dest += "/" if self.file_check?(:file => dest, :tests => :directory) && dest !~ /\/$/
|
236
236
|
|
237
237
|
files.each do |file|
|
238
238
|
begin
|
@@ -264,7 +264,7 @@ module Cowtech
|
|
264
264
|
break if !rv
|
265
265
|
end
|
266
266
|
else # If we are copying or moving to a file
|
267
|
-
if !files.kind_of?(String)
|
267
|
+
if !files.kind_of?(String) && !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
|
@@ -275,7 +275,7 @@ module Cowtech
|
|
275
275
|
end
|
276
276
|
|
277
277
|
begin
|
278
|
-
if move
|
278
|
+
if move then
|
279
279
|
FileUtils.move(files, dest, {:noop => @console.skip_commands, :verbose => @console.skip_commands})
|
280
280
|
else
|
281
281
|
FileUtils.cp(files, dest, {:noop => @console.skip_commands, :verbose => @console.skip_commands})
|
@@ -305,7 +305,7 @@ module Cowtech
|
|
305
305
|
def rename(args)
|
306
306
|
rv = true
|
307
307
|
|
308
|
-
if src.is_a?(String)
|
308
|
+
if src.is_a?(String) && dst.is_a?(String) then
|
309
309
|
rv = self.copy(:from => src, :to => dst, :show_errors => args[:show_errors], :fatal => args[:fatal])
|
310
310
|
else
|
311
311
|
@console.error("Cowtech::Lib::Shell#rename: Both :src and :dst arguments must be a string.", :dots => false, :fatal => args[:fatal]) if args[:show_error]
|
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.6.
|
4
|
+
version: 1.9.6.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: 2011-07-
|
12
|
+
date: 2011-07-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: open4
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153527200 !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: *2153527200
|
25
25
|
description: A general purpose utility library.
|
26
26
|
email: shogun_panda@me.com
|
27
27
|
executables: []
|