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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bad275062a9f72ff201812eb6cd7871b9321b80b57f379f817cab483de42b738
4
- data.tar.gz: e3cb70b12fe4831a4fdd194eaa4c67118efcfd9ffc0f1903524d74bdaf805e1a
3
+ metadata.gz: 46f243576af73a6b5e4b56a097e4876377f2f4b0b2871ea013955d6eb75addd0
4
+ data.tar.gz: c44bcb2a54d9f1c3e9d5c19543805ba16f0bd224f5ece98acb02da3be071bf31
5
5
  SHA512:
6
- metadata.gz: 43cc9f0156398b92a5d1c7370c6c8c7dcf61d80e4ad9b18bec8a4a5bedceec7aa9e9af40e5d801554c7369aa746bac98c204ad949d2d27b381c4e14cbec93312
7
- data.tar.gz: '0948e6f13057dd174140d84a7845c33a25e758a9ef018e10afb9c75bb734e87dffaf191e81091e01fe8c1dc9ff66437672364343d7ffc054f76cf0d591ebec1d'
6
+ metadata.gz: 2d04141ca190c6a98bd4481156708c9fbff7f9550324bee3612c283959ad94b90efaf33484fd77b6425f3320ecf6e2e8996422e307506f837f07785267cf5686
7
+ data.tar.gz: 761917986fb8e915fc189e2d4cee710bd39ac44c968b421cca4ee65affd0d07ec7de9455a3e46e15beb1ee09110e966c72bc2be01e9746254256e50067308d88
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ ------------------
2
+ 0.4.1 (2026-06-05)
3
+ ------------------
4
+
5
+ * Fix definition on RunError
6
+ * In DEBUG=1 mode, run() call stack depth can be tuned with DEBUG_CALL_STACK=<n>
7
+
1
8
  ------------------
2
9
  0.4.0 (2026-06-05)
3
10
  ------------------
@@ -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.is_a?(Module)
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 #{caller[1]}")
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
 
@@ -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
- possible_name = base.name ? "#{base.name}Error" : nil
7
+ return if base == nil
8
8
 
9
- superclass = if possible_name && Object.const_defined?(possible_name)
10
- Object.const_get(possible_name)
11
- elsif base.const_defined?(:Error)
12
- base.const_get(:Error)
13
- else
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, superclass)
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
- # Some class have their own execAction, because object creation might be tricky.
121
- if kClass.respond_to?(:execAction)
122
- ret = kClass.execAction(opts, action)
123
- else
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}")
@@ -1,31 +1,19 @@
1
1
  module CLIClassTool
2
- class RunError < StandardError
3
- attr_reader :err_code, :output
2
+ def self.define_run_error(parent_module, superclass)
3
+ klass = Class.new(superclass)
4
4
 
5
- def initialize(err_code, output = nil)
6
- @err_code = err_code
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
- def initialize(err_code, output = nil)
20
- @err_code = err_code
21
- @output = output
22
- super("Command failed with exit status #{err_code}#{output ? "\n#{output}" : ''}")
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
- end
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli_class_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Morey