cmdx 0.3.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da7809a9d556cc2cb4cc5734fe52790f4e964ccc437728e1c78cef2a6e2121ec
4
- data.tar.gz: 9577047cd8a98bc19fe81c02366aebf70c295e738e3083c478ab670c8af55048
3
+ metadata.gz: 4564456f58ece0df7606a6eee705e3ed5225b66e8cb1b3feae426ae990204fe4
4
+ data.tar.gz: 412ffb7cfdfbbd71da1c34f2a8bb871f9d9c67b7ef89ab7453af969c4bf6340b
5
5
  SHA512:
6
- metadata.gz: 3101e89eafcaf552fa64db81fdc0547628e23636564097ae91fb5dc726cbe25bcfbb6c44a04619cbbfcfe41f29f9a42a658bcd045a1a035f85b0c098d20a6038
7
- data.tar.gz: 97450b9d1018dfc80d73fac8b0072356c4a1e05f39fc377cbf517468a412c77041bb1376ae0b3a72fb34575709fa169115ebf69ae7285a75fe41d453b21ee247
6
+ metadata.gz: 9f416759468491771ec5c1ae8985ceef482287680cd494fc4747adea90a570d894a9725958ffd08167cd9c68e59311ea2f4080997ea1e1edf58db12433fad036
7
+ data.tar.gz: 6e0c6a16bfede183fb61633f55e5bd53bed529b75a2d3fcdbb763885f28d2a614c94abc0cabb178c5743bef99e404648f126c31b0378a0b7da5125d2d8b888a1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2025-03-21
4
+
5
+ ### Added
6
+ - Add `to_a` alias on array of hashes serializers
7
+ - Add `state`, `status`, `outcome`, and `runtime` to run serializer
8
+ - Add `on_[state]` and `on_[status]` based result callback handlers
9
+ - Add `on_executed` state task hook
10
+ - Add `on_good` and `on_bad` status task hook
11
+ ### Changed
12
+ - Changed status and state hook order
13
+
14
+ ## [0.4.0] - 2025-03-17
15
+
16
+ ### Added
17
+ - Add ansi util
18
+ - Add string to json parsing in hash coercion
19
+ - Add string to json parsing in array coercion
20
+ ### Changed
21
+ - Skip assigning log settings if logger is nil
22
+ - Improve ANSI escape sequence
23
+ - Improve run inspector output
24
+
3
25
  ## [0.3.0] - 2025-03-14
4
26
  ### Added
5
27
  - Add `progname` to logger instances
data/docs/hooks.md CHANGED
@@ -41,13 +41,16 @@ The hook methods support the following options:
41
41
  Hook types are executed in the following order:
42
42
 
43
43
  ```ruby
44
- 1. before_execution
45
- 2. on_executing
46
- 3. before_validation
47
- 4. after_validation
48
- 5. on_[success, skipped, failed]
49
- 6. on_[complete, interrupted]
50
- 7. after_execution
44
+ 0. before_execution
45
+ 1. on_executing
46
+ 2. before_validation
47
+ 3. after_validation
48
+ 4. on_[complete, interrupted]
49
+ 5. on_executed
50
+ 6. on_[success, skipped, failed]
51
+ 7. on_good
52
+ 8. on_bad
53
+ 9. after_execution
51
54
  ```
52
55
 
53
56
  > [!IMPORTANT]
data/docs/logging.md CHANGED
@@ -11,27 +11,27 @@ Built-in log formatters are:
11
11
 
12
12
  #### Success:
13
13
  ```txt
14
- I, [2022-07-17T18:43:15.000000 #3784] INFO -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task task=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=complete status=success outcome=success metadata={} runtime=0 origin=CMDx
14
+ I, [2022-07-17T18:43:15.000000 #3784] INFO -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task class=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=complete status=success outcome=success metadata={} runtime=0 origin=CMDx
15
15
  ```
16
16
 
17
17
  #### Skipped:
18
18
  ```txt
19
- W, [2022-07-17T18:43:15.000000 #3784] WARN -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task task=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=skipped outcome=skipped metadata={} runtime=0 origin=CMDx
19
+ W, [2022-07-17T18:43:15.000000 #3784] WARN -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task class=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=skipped outcome=skipped metadata={} runtime=0 origin=CMDx
20
20
  ```
21
21
 
22
22
  #### Failed:
23
23
  ```txt
24
- E, [2022-07-17T18:43:15.000000 #3784] ERROR -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task task=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=failed outcome=failed metadata={} runtime=0 origin=CMDx
24
+ E, [2022-07-17T18:43:15.000000 #3784] ERROR -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task class=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=failed outcome=failed metadata={} runtime=0 origin=CMDx
25
25
  ```
26
26
 
27
27
  #### Level 1 subtask failure:
28
28
  ```txt
29
- E, [2022-07-17T18:43:15.000000 #3784] ERROR -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task task=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=failed outcome=interrupted metadata={} runtime=0 caused_failure={index: 1, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", task: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "failed", metadata: {}, runtime: 0} threw_failure={index: 1, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", task: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "failed", metadata: {}, runtime: 0} origin=CMDx
29
+ E, [2022-07-17T18:43:15.000000 #3784] ERROR -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task class=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=failed outcome=interrupted metadata={} runtime=0 caused_failure={index: 1, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", class: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "failed", metadata: {}, runtime: 0} threw_failure={index: 1, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", class: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "failed", metadata: {}, runtime: 0} origin=CMDx
30
30
  ```
31
31
 
32
32
  #### Level 2+ subtask failure:
33
33
  ```txt
34
- E, [2022-07-17T18:43:15.000000 #3784] ERROR -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task task=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=failed outcome=interrupted metadata={} runtime=0 caused_failure={index: 2, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", task: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "failed", metadata: {}, runtime: 0} threw_failure={index: 1, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", task: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "interrupted", metadata: {}, runtime: 0} origin=CMDx
34
+ E, [2022-07-17T18:43:15.000000 #3784] ERROR -- SimulationTask: index=0 run_id=018c2b95-b764-7615-a924-cc5b910ed1e5 type=Task class=SimulationTask id=018c2b95-b764-7615-a924-cc5b910ed1e5 tags=[] state=interrupted status=failed outcome=interrupted metadata={} runtime=0 caused_failure={index: 2, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", class: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "failed", metadata: {}, runtime: 0} threw_failure={index: 1, run_id: "018c2b95-b764-7615-a924-cc5b910ed1e5", type: "Task", class: "SimulationTask", id: "018c2b95-b764-7615-a924-cc5b910ed1e5", tags: [], state: "interrupted", status: "failed", outcome: "interrupted", metadata: {}, runtime: 0} origin=CMDx
35
35
  ```
36
36
 
37
37
  ## Logger
@@ -25,6 +25,27 @@ result.interrupted? #=> false
25
25
  result.executed?
26
26
  ```
27
27
 
28
+ ## Handlers
29
+
30
+ Results can be used to trigger state based callbacks. Handlers require a block
31
+ and will have the result available as local variable. Callback handlers can be
32
+ chained and repeated.
33
+
34
+ ```ruby
35
+ result = ProcessOrderTask.call
36
+ result.on_complete { do_work }
37
+
38
+ # - or -
39
+
40
+ ProcessOrderTask
41
+ .call(...)
42
+ .on_executing { do_work }
43
+ .on_executed { |result| $statsd.increment(result.state) }
44
+ ```
45
+
46
+ > [!TIP]
47
+ > Handlers help execute you logical branches without `if/else` blocks.
48
+
28
49
  ---
29
50
 
30
51
  - **Prev:** [Outcomes - Statuses](https://github.com/drexed/cmdx/blob/main/docs/outcomes/statuses.md)
@@ -27,6 +27,27 @@ result.good? #=> true
27
27
  result.bad? #=> true
28
28
  ```
29
29
 
30
+ ## Handlers
31
+
32
+ Results can be used to trigger status based callbacks. Handlers require a block
33
+ and will have the result available as local variable. Callback handlers can be
34
+ chained and repeated.
35
+
36
+ ```ruby
37
+ result = ProcessOrderTask.call
38
+ result.on_success { do_work }
39
+
40
+ # - or -
41
+
42
+ ProcessOrderTask
43
+ .call(...)
44
+ .on_success { do_work }
45
+ .on_bad { |result| $statsd.increment(result.state) }
46
+ ```
47
+
48
+ > [!TIP]
49
+ > Handlers help execute you logical branches without `if/else` blocks.
50
+
30
51
  ---
31
52
 
32
53
  - **Prev:** [Outcomes - Result](https://github.com/drexed/cmdx/blob/main/docs/outcomes/result.md)
@@ -7,7 +7,11 @@ module CMDx
7
7
  module_function
8
8
 
9
9
  def call(value, _options = {})
10
- Array(value)
10
+ if value.is_a?(::String) && value.start_with?("[")
11
+ JSON.parse(value)
12
+ else
13
+ Array(value)
14
+ end
11
15
  end
12
16
 
13
17
  end
@@ -8,11 +8,16 @@ module CMDx
8
8
 
9
9
  def call(value, _options = {})
10
10
  case value.class.name
11
- when "Hash", "ActionController::Parameters" then value
12
- when "Array" then ::Hash[*value]
13
- else raise_coercion_error!
11
+ when "Hash", "ActionController::Parameters"
12
+ value
13
+ when "Array"
14
+ ::Hash[*value]
15
+ when "String"
16
+ value.start_with?("{") ? JSON.parse(value) : raise_coercion_error!
17
+ else
18
+ raise_coercion_error!
14
19
  end
15
- rescue ArgumentError, TypeError
20
+ rescue ArgumentError, TypeError, JSON::ParserError
16
21
  raise_coercion_error!
17
22
  end
18
23
 
@@ -14,7 +14,7 @@ module CMDx
14
14
 
15
15
  def reset_configuration!
16
16
  @configuration = LazyStruct.new(
17
- logger: ::Logger.new($stdout, formatter: CMDx::LogFormatters::Json.new),
17
+ logger: ::Logger.new($stdout, formatter: CMDx::LogFormatters::Line.new),
18
18
  task_halt: CMDx::Result::FAILED,
19
19
  task_timeout: nil,
20
20
  batch_halt: CMDx::Result::FAILED,
data/lib/cmdx/logger.rb CHANGED
@@ -6,10 +6,14 @@ module CMDx
6
6
  module_function
7
7
 
8
8
  def call(task)
9
- logger = task.task_setting(:logger)
10
- logger.formatter = task.task_setting(:log_formatter) if task.task_setting?(:log_formatter)
11
- logger.level = task.task_setting(:log_level) if task.task_setting?(:log_level)
12
- logger.progname = task
9
+ logger = task.task_setting(:logger)
10
+
11
+ unless logger.nil?
12
+ logger.formatter = task.task_setting(:log_formatter) if task.task_setting?(:log_formatter)
13
+ logger.level = task.task_setting(:log_level) if task.task_setting?(:log_level)
14
+ logger.progname = task
15
+ end
16
+
13
17
  logger
14
18
  end
15
19
 
@@ -3,19 +3,20 @@
3
3
  module CMDx
4
4
  module LoggerAnsi
5
5
 
6
- SEVERITY_COLOR_CODES = {
7
- "D" => 34, # DEBUG - Blue
8
- "I" => 32, # INFO - Green
9
- "W" => 33, # WARN - Yellow
10
- "E" => 31, # ERROR - Red
11
- "F" => 35 # FATAL - Magenta
6
+ SEVERITY_COLORS = {
7
+ "D" => :blue,
8
+ "I" => :green,
9
+ "W" => :yellow,
10
+ "E" => :red,
11
+ "F" => :magenta
12
12
  }.freeze
13
13
 
14
14
  module_function
15
15
 
16
16
  def call(s)
17
- c = SEVERITY_COLOR_CODES[s[0]] || 39 # Default
18
- "\e[1;#{c}m#{s}\e[0m"
17
+ color = SEVERITY_COLORS[s[0]] || :default
18
+
19
+ Utils::AnsiColor.call(s, color:, mode: :bold)
19
20
  end
20
21
 
21
22
  end
@@ -18,6 +18,7 @@ module CMDx
18
18
  def to_h
19
19
  ParametersSerializer.call(self)
20
20
  end
21
+ alias to_a to_h
21
22
 
22
23
  def to_s
23
24
  ParametersInspector.call(self)
data/lib/cmdx/result.rb CHANGED
@@ -26,6 +26,14 @@ module CMDx
26
26
  STATES.each do |s|
27
27
  # eg: executing?
28
28
  define_method(:"#{s}?") { state == s }
29
+
30
+ # eg: on_interrupted { ... }
31
+ define_method(:"on_#{s}") do |&block|
32
+ raise ArgumentError, "a block is required" unless block
33
+
34
+ block.call(self) if send(:"#{s}?")
35
+ self
36
+ end
29
37
  end
30
38
 
31
39
  def executed!
@@ -36,6 +44,13 @@ module CMDx
36
44
  complete? || interrupted?
37
45
  end
38
46
 
47
+ def on_executed(&)
48
+ raise ArgumentError, "a block is required" unless block_given?
49
+
50
+ yield(self) if executed?
51
+ self
52
+ end
53
+
39
54
  def executing!
40
55
  return if executing?
41
56
 
@@ -69,16 +84,38 @@ module CMDx
69
84
  STATUSES.each do |s|
70
85
  # eg: skipped?
71
86
  define_method(:"#{s}?") { status == s }
87
+
88
+ # eg: on_failed { ... }
89
+ define_method(:"on_#{s}") do |&block|
90
+ raise ArgumentError, "a block is required" unless block
91
+
92
+ block.call(self) if send(:"#{s}?")
93
+ self
94
+ end
72
95
  end
73
96
 
74
97
  def good?
75
98
  !failed?
76
99
  end
77
100
 
101
+ def on_good(&)
102
+ raise ArgumentError, "a block is required" unless block_given?
103
+
104
+ yield(self) if good?
105
+ self
106
+ end
107
+
78
108
  def bad?
79
109
  !success?
80
110
  end
81
111
 
112
+ def on_bad(&)
113
+ raise ArgumentError, "a block is required" unless block_given?
114
+
115
+ yield(self) if bad?
116
+ self
117
+ end
118
+
82
119
  def skip!(**metadata)
83
120
  return if skipped?
84
121
 
@@ -3,23 +3,24 @@
3
3
  module CMDx
4
4
  module ResultAnsi
5
5
 
6
- STATE_COLOR_CODES = {
7
- Result::INITIALIZED => 34, # Blue
8
- Result::EXECUTING => 33, # Yellow
9
- Result::COMPLETE => 32, # Green
10
- Result::INTERRUPTED => 31 # Red
6
+ STATE_COLORS = {
7
+ Result::INITIALIZED => :blue,
8
+ Result::EXECUTING => :yellow,
9
+ Result::COMPLETE => :green,
10
+ Result::INTERRUPTED => :red
11
11
  }.freeze
12
- STATUS_COLOR_CODES = {
13
- Result::SUCCESS => 32, # Green
14
- Result::SKIPPED => 33, # Yellow
15
- Result::FAILED => 31 # Red
12
+ STATUS_COLORS = {
13
+ Result::SUCCESS => :green,
14
+ Result::SKIPPED => :yellow,
15
+ Result::FAILED => :red
16
16
  }.freeze
17
17
 
18
18
  module_function
19
19
 
20
20
  def call(s)
21
- c = STATE_COLOR_CODES[s] || STATUS_COLOR_CODES[s] || 39 # Default
22
- "\e[1;#{c}m#{s}\e[0m"
21
+ color = STATE_COLORS[s] || STATUS_COLORS[s] || :default
22
+
23
+ Utils::AnsiColor.call(s, color:)
23
24
  end
24
25
 
25
26
  end
@@ -4,7 +4,7 @@ module CMDx
4
4
  module ResultInspector
5
5
 
6
6
  ORDERED_KEYS = %i[
7
- task type index id state status outcome metadata
7
+ class type index id state status outcome metadata
8
8
  tags pid runtime caused_failure threw_failure
9
9
  ].freeze
10
10
 
@@ -17,10 +17,10 @@ module CMDx
17
17
  value = result[key]
18
18
 
19
19
  case key
20
- when :task
20
+ when :class
21
21
  "#{value}:"
22
22
  when :caused_failure, :threw_failure
23
- "#{key}=<[#{value[:index]}] #{value[:task]}: #{value[:id]}>"
23
+ "#{key}=<[#{value[:index]}] #{value[:class]}: #{value[:id]}>"
24
24
  else
25
25
  "#{key}=#{value}"
26
26
  end
@@ -12,7 +12,9 @@ module CMDx
12
12
  module_function
13
13
 
14
14
  def call(result)
15
- logger = result.task.send(:logger)
15
+ logger = result.task.send(:logger)
16
+ return if logger.nil?
17
+
16
18
  severity = STATUS_TO_SEVERITY[result.status]
17
19
 
18
20
  logger.with_level(severity) do
data/lib/cmdx/run.rb CHANGED
@@ -21,6 +21,7 @@ module CMDx
21
21
  def to_h
22
22
  RunSerializer.call(self)
23
23
  end
24
+ alias to_a to_h
24
25
 
25
26
  def to_s
26
27
  RunInspector.call(self)
@@ -3,18 +3,23 @@
3
3
  module CMDx
4
4
  module RunInspector
5
5
 
6
- ORDERED_KEYS = %i[
6
+ FOOTER_KEYS = %i[
7
7
  state status outcome runtime
8
8
  ].freeze
9
9
 
10
10
  module_function
11
11
 
12
12
  def call(run)
13
- header = "Run: #{run.id}"
14
- footer = ORDERED_KEYS.map { |key| "#{key}=#{run.send(key)}" }.join(" ")
13
+ header = "\nrun: #{run.id}"
14
+ footer = FOOTER_KEYS.map { |key| "#{key}: #{run.send(key)}" }.join(" | ")
15
15
  spacer = "=" * [header.size, footer.size].max
16
16
 
17
- run.results.map(&:to_s).unshift(header, spacer).push(spacer, footer).join("\n")
17
+ run
18
+ .results
19
+ .map { |r| r.to_h.except(:run_id).pretty_inspect }
20
+ .unshift(header, "#{spacer}\n")
21
+ .push(spacer, "#{footer}\n\n")
22
+ .join("\n")
18
23
  end
19
24
 
20
25
  end
@@ -8,6 +8,10 @@ module CMDx
8
8
  def call(run)
9
9
  {
10
10
  id: run.id,
11
+ state: run.state,
12
+ status: run.status,
13
+ outcome: run.outcome,
14
+ runtime: run.runtime,
11
15
  results: run.results.map(&:to_h)
12
16
  }
13
17
  end
data/lib/cmdx/task.rb CHANGED
@@ -8,6 +8,9 @@ module CMDx
8
8
  :after_validation,
9
9
  :before_execution,
10
10
  :after_execution,
11
+ :on_executed,
12
+ :on_good,
13
+ :on_bad,
11
14
  *Result::STATUSES.map { |s| :"on_#{s}" },
12
15
  *Result::STATES.map { |s| :"on_#{s}" }
13
16
  ].freeze
@@ -103,8 +106,12 @@ module CMDx
103
106
  end
104
107
 
105
108
  def after_call
106
- TaskHook.call(self, :"on_#{result.status}")
107
109
  TaskHook.call(self, :"on_#{result.state}")
110
+ TaskHook.call(self, :on_executed) if result.executed?
111
+
112
+ TaskHook.call(self, :"on_#{result.status}")
113
+ TaskHook.call(self, :on_good) if result.good?
114
+ TaskHook.call(self, :on_bad) if result.bad?
108
115
 
109
116
  TaskHook.call(self, :after_execution)
110
117
  end
@@ -10,7 +10,7 @@ module CMDx
10
10
  index: task.result.index,
11
11
  run_id: task.run.id,
12
12
  type: task.is_a?(Batch) ? "Batch" : "Task",
13
- task: task.class.name,
13
+ class: task.class.name,
14
14
  id: task.id,
15
15
  tags: task.task_setting(:tags)
16
16
  }
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CMDx
4
+ module Utils
5
+ module AnsiColor
6
+
7
+ COLOR_CODES = {
8
+ black: 30,
9
+ red: 31,
10
+ green: 32,
11
+ yellow: 33,
12
+ blue: 34,
13
+ magenta: 35,
14
+ cyan: 36,
15
+ white: 37,
16
+ default: 39,
17
+ light_black: 90,
18
+ light_red: 91,
19
+ light_green: 92,
20
+ light_yellow: 93,
21
+ light_blue: 94,
22
+ light_magenta: 95,
23
+ light_cyan: 96,
24
+ light_white: 97
25
+ }.freeze
26
+ MODE_CODES = {
27
+ default: 0,
28
+ bold: 1,
29
+ dim: 2,
30
+ italic: 3,
31
+ underline: 4,
32
+ blink: 5,
33
+ blink_slow: 5,
34
+ blink_fast: 6,
35
+ invert: 7,
36
+ hide: 8,
37
+ strike: 9,
38
+ double_underline: 20,
39
+ reveal: 28,
40
+ overlined: 53
41
+ }.freeze
42
+
43
+ module_function
44
+
45
+ def call(value, color:, mode: :default)
46
+ color_code = COLOR_CODES.fetch(color)
47
+ mode_code = MODE_CODES.fetch(mode)
48
+
49
+ "\e[#{mode_code};#{color_code};49m#{value}\e[0m"
50
+ end
51
+
52
+ end
53
+ end
54
+ end
data/lib/cmdx/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CMDx
4
4
 
5
- VERSION = "0.3.0"
5
+ VERSION = "0.5.0"
6
6
 
7
7
  end
data/lib/cmdx.rb CHANGED
@@ -5,6 +5,7 @@ require "date"
5
5
  require "i18n"
6
6
  require "json"
7
7
  require "logger"
8
+ require "pp"
8
9
  require "securerandom"
9
10
  require "time"
10
11
  require "timeout"
@@ -41,6 +42,7 @@ require_relative "cmdx/validators/inclusion"
41
42
  require_relative "cmdx/validators/length"
42
43
  require_relative "cmdx/validators/numeric"
43
44
  require_relative "cmdx/validators/presence"
45
+ require_relative "cmdx/utils/ansi_color"
44
46
  require_relative "cmdx/utils/log_timestamp"
45
47
  require_relative "cmdx/utils/name_affix"
46
48
  require_relative "cmdx/utils/monotonic_runtime"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmdx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-14 00:00:00.000000000 Z
10
+ date: 2025-03-21 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -246,6 +246,7 @@ files:
246
246
  - lib/cmdx/task.rb
247
247
  - lib/cmdx/task_hook.rb
248
248
  - lib/cmdx/task_serializer.rb
249
+ - lib/cmdx/utils/ansi_color.rb
249
250
  - lib/cmdx/utils/log_timestamp.rb
250
251
  - lib/cmdx/utils/monotonic_runtime.rb
251
252
  - lib/cmdx/utils/name_affix.rb