cli_class_tool 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/lib/cli_class_tool/common.rb +10 -2
- data/lib/cli_class_tool/utils.rb +11 -16
- data/lib/cli_class_tool.rb +10 -22
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46f243576af73a6b5e4b56a097e4876377f2f4b0b2871ea013955d6eb75addd0
|
|
4
|
+
data.tar.gz: c44bcb2a54d9f1c3e9d5c19543805ba16f0bd224f5ece98acb02da3be071bf31
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d04141ca190c6a98bd4481156708c9fbff7f9550324bee3612c283959ad94b90efaf33484fd77b6425f3320ecf6e2e8996422e307506f837f07785267cf5686
|
|
7
|
+
data.tar.gz: 761917986fb8e915fc189e2d4cee710bd39ac44c968b421cca4ee65affd0d07ec7de9455a3e46e15beb1ee09110e966c72bc2be01e9746254256e50067308d88
|
data/CHANGELOG
CHANGED
|
@@ -25,7 +25,8 @@ module CLIClassTool
|
|
|
25
25
|
# @param obj [Object,Class] Object or class to get the Module from
|
|
26
26
|
# @raise [StandardError] If command failed
|
|
27
27
|
def obj_to_parent_mod(obj)
|
|
28
|
-
return obj if obj.
|
|
28
|
+
return obj if obj.class == Module
|
|
29
|
+
|
|
29
30
|
theClass = obj.is_a?(Class) ? obj : obj.class
|
|
30
31
|
if theClass.name.nil?
|
|
31
32
|
return Object
|
|
@@ -137,7 +138,14 @@ module CLIClassTool
|
|
|
137
138
|
# @param cmd_type [String] Type of command (e.g., 'git')
|
|
138
139
|
# @param cmd [String] The command string
|
|
139
140
|
def cmd_debug(cmd_type, cmd)
|
|
140
|
-
log(:DEBUG, "Called from
|
|
141
|
+
log(:DEBUG, "Called from:")
|
|
142
|
+
depth=1
|
|
143
|
+
if ENV["DEBUG_CALL_DEPTH"].to_s() != ""
|
|
144
|
+
depth = ENV["DEBUG_CALL_DEPTH"].to_i()
|
|
145
|
+
end
|
|
146
|
+
[ depth, caller.length].min.downto(1){|x|
|
|
147
|
+
log(:DEBUG, " #{caller[x]}")
|
|
148
|
+
}
|
|
141
149
|
log(:DEBUG, "Running #{cmd_type} command '#{cmd}'")
|
|
142
150
|
end
|
|
143
151
|
|
data/lib/cli_class_tool/utils.rb
CHANGED
|
@@ -4,17 +4,16 @@ module CLIClassTool
|
|
|
4
4
|
|
|
5
5
|
# Hook called when a module extends CLIClassTool::Utils
|
|
6
6
|
def self.extended(base)
|
|
7
|
-
|
|
7
|
+
return if base == nil
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
CLIClassTool::RunError
|
|
9
|
+
lower_mod = base.name.split('::')[-1]
|
|
10
|
+
superclass_name = "#{base.name}::#{lower_mod}Error"
|
|
11
|
+
|
|
12
|
+
if ! Object.const_defined?(superclass_name)
|
|
13
|
+
raise("Could not find a base error class named #{superclass_name}")
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
CLIClassTool.define_run_error(base,
|
|
16
|
+
CLIClassTool.define_run_error(base, Object.const_get(superclass_name))
|
|
18
17
|
end
|
|
19
18
|
|
|
20
19
|
# Convert a string to an action symbol, validating it against available actions
|
|
@@ -117,14 +116,10 @@ module CLIClassTool
|
|
|
117
116
|
|
|
118
117
|
self._runOnClass(action, nil) {|kClass|
|
|
119
118
|
begin
|
|
120
|
-
#
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# Use load factory method if defined, else fall back to .new
|
|
125
|
-
obj = kClass.respond_to?(:load) ? kClass.load() : kClass.new()
|
|
126
|
-
ret = obj.public_send(action, opts)
|
|
127
|
-
end
|
|
119
|
+
# Use load factory method if defined, else fall back to .new
|
|
120
|
+
obj = kClass.respond_to?(:load) ? kClass.load() : kClass.new()
|
|
121
|
+
ret = obj.public_send(action, opts)
|
|
122
|
+
|
|
128
123
|
return ret.is_a?(Integer) ? ret : 0
|
|
129
124
|
rescue caught_error_class => e
|
|
130
125
|
puts("# " + "ERROR".red().to_s() + ": Action '#{action}' failed: #{e.message}")
|
data/lib/cli_class_tool.rb
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
module CLIClassTool
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
def self.define_run_error(parent_module, superclass)
|
|
3
|
+
klass = Class.new(superclass)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@output = output
|
|
8
|
-
super("Command failed with exit status #{err_code}#{output ? "\n#{output}" : ''}")
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.define_run_error(parent_module, superclass = CLIClassTool::RunError)
|
|
13
|
-
klass = Class.new(superclass)
|
|
14
|
-
|
|
15
|
-
if !(superclass <= CLIClassTool::RunError)
|
|
16
|
-
klass.class_eval do
|
|
17
|
-
attr_reader :err_code, :output
|
|
5
|
+
klass.class_eval do
|
|
6
|
+
attr_reader :err_code, :msg
|
|
18
7
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
def initialize(err_code, output = nil)
|
|
9
|
+
@err_code = err_code
|
|
10
|
+
@msg = output
|
|
11
|
+
super("Command failed with exit status #{err_code}")
|
|
12
|
+
end
|
|
23
13
|
end
|
|
24
|
-
|
|
14
|
+
parent_module.const_set(:RunError, klass)
|
|
25
15
|
end
|
|
26
16
|
|
|
27
|
-
parent_module.const_set(:RunError, klass)
|
|
28
|
-
end
|
|
29
17
|
end
|
|
30
18
|
|
|
31
19
|
require_relative 'cli_class_tool/string'
|