cmdx 0.3.0 → 0.4.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/docs/logging.md +5 -5
- data/lib/cmdx/coercions/array.rb +5 -1
- data/lib/cmdx/coercions/hash.rb +9 -4
- data/lib/cmdx/configuration.rb +1 -1
- data/lib/cmdx/logger.rb +8 -4
- data/lib/cmdx/logger_ansi.rb +9 -8
- data/lib/cmdx/result_ansi.rb +12 -11
- data/lib/cmdx/result_inspector.rb +3 -3
- data/lib/cmdx/result_logger.rb +3 -1
- data/lib/cmdx/run_inspector.rb +9 -4
- data/lib/cmdx/task_serializer.rb +1 -1
- data/lib/cmdx/utils/ansi_color.rb +54 -0
- data/lib/cmdx/version.rb +1 -1
- data/lib/cmdx.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00e2b2067ace8ed3afdb75bc07e3f3c5ec3ed40233a63cc3a9abc495c3a3199c
|
4
|
+
data.tar.gz: 053c7a3a6e3c70808b4dba6d916a35419ee0c858145dbace0d83d89e0583d05a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2de61e9b7e43d9e1187b4c6c925c930ae55163a5075ac624f4a9c29595588b10aacd007d64654397dc458a9c704d9175dd884eadafbef614bb8f01182f022cf0
|
7
|
+
data.tar.gz: 52dcb48c2e9538d33fea460946fde8f25814127aa490895fc4a676f865423d0b915ad1e7c5daae88ebe46e4bff01a36f850fa704bff312fa938ed5e3a7ea879a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.0] - 2025-03-17
|
4
|
+
|
5
|
+
### Added
|
6
|
+
- Add ansi util
|
7
|
+
- Add string to json parsing in hash coercion
|
8
|
+
- Add string to json parsing in array coercion
|
9
|
+
### Changed
|
10
|
+
- Skip assigning log settings if logger is nil
|
11
|
+
- Improve ANSI escape sequence
|
12
|
+
- Improve run inspector output
|
13
|
+
|
3
14
|
## [0.3.0] - 2025-03-14
|
4
15
|
### Added
|
5
16
|
- Add `progname` to logger instances
|
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
|
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
|
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
|
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
|
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
|
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
|
data/lib/cmdx/coercions/array.rb
CHANGED
data/lib/cmdx/coercions/hash.rb
CHANGED
@@ -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"
|
12
|
-
|
13
|
-
|
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
|
|
data/lib/cmdx/configuration.rb
CHANGED
@@ -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::
|
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
|
10
|
-
|
11
|
-
logger.
|
12
|
-
|
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
|
|
data/lib/cmdx/logger_ansi.rb
CHANGED
@@ -3,19 +3,20 @@
|
|
3
3
|
module CMDx
|
4
4
|
module LoggerAnsi
|
5
5
|
|
6
|
-
|
7
|
-
"D" =>
|
8
|
-
"I" =>
|
9
|
-
"W" =>
|
10
|
-
"E" =>
|
11
|
-
"F" =>
|
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
|
-
|
18
|
-
|
17
|
+
color = SEVERITY_COLORS[s[0]] || :default
|
18
|
+
|
19
|
+
Utils::AnsiColor.call(s, color:, mode: :bold)
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
data/lib/cmdx/result_ansi.rb
CHANGED
@@ -3,23 +3,24 @@
|
|
3
3
|
module CMDx
|
4
4
|
module ResultAnsi
|
5
5
|
|
6
|
-
|
7
|
-
Result::INITIALIZED =>
|
8
|
-
Result::EXECUTING =>
|
9
|
-
Result::COMPLETE =>
|
10
|
-
Result::INTERRUPTED =>
|
6
|
+
STATE_COLORS = {
|
7
|
+
Result::INITIALIZED => :blue,
|
8
|
+
Result::EXECUTING => :yellow,
|
9
|
+
Result::COMPLETE => :green,
|
10
|
+
Result::INTERRUPTED => :red
|
11
11
|
}.freeze
|
12
|
-
|
13
|
-
Result::SUCCESS =>
|
14
|
-
Result::SKIPPED =>
|
15
|
-
Result::FAILED =>
|
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
|
-
|
22
|
-
|
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
|
-
|
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 :
|
20
|
+
when :class
|
21
21
|
"#{value}:"
|
22
22
|
when :caused_failure, :threw_failure
|
23
|
-
"#{key}=<[#{value[:index]}] #{value[:
|
23
|
+
"#{key}=<[#{value[:index]}] #{value[:class]}: #{value[:id]}>"
|
24
24
|
else
|
25
25
|
"#{key}=#{value}"
|
26
26
|
end
|
data/lib/cmdx/result_logger.rb
CHANGED
data/lib/cmdx/run_inspector.rb
CHANGED
@@ -3,18 +3,23 @@
|
|
3
3
|
module CMDx
|
4
4
|
module RunInspector
|
5
5
|
|
6
|
-
|
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 = "
|
14
|
-
footer =
|
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
|
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
|
data/lib/cmdx/task_serializer.rb
CHANGED
@@ -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
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-17 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
|