cli_class_tool 0.5.1 → 1.1.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 +12 -0
- data/README.md +52 -0
- data/lib/cli_class_tool/common.rb +21 -6
- data/lib/cli_class_tool/string.rb +95 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 645eabaadb2f9f7b6497f524dc2e847bbe6fa2b3bd0085449e7a5c6e49e6d943
|
|
4
|
+
data.tar.gz: 94cb2bfe852dce7a0f1a55a7888a813e4beea307f0a41c056c69d26f0914e4e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 576fc426eedf2ed6578dce762fae533432cee75c1dce31d31ebf1c44b2b6c82b0a6418d74670fb5b6a6812b278c0444cc8295adb79d5fa2be4507cbbc9136d16
|
|
7
|
+
data.tar.gz: 4c6544ef6d4eecb54d5f2e7de75106e33936523d3e2bcea82ad729e0a388d9e33b193727b67637ef9901f29c23fccfa5ee9caed484043c4b2e7e8f60da7ca7db
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
------------------
|
|
2
|
+
1.1.0 (2026-09-09)
|
|
3
|
+
------------------
|
|
4
|
+
|
|
5
|
+
* Extend String class with support for all 16 standard/high-intensity ANSI colors and a chainable `.bold` method that merges ANSI escape sequences
|
|
6
|
+
|
|
7
|
+
------------------
|
|
8
|
+
1.0.0 (2026-09-09)
|
|
9
|
+
------------------
|
|
10
|
+
|
|
11
|
+
* Switch confirm to optional hash-style arguments (:ignored_default, :allowed_reps, :usage), dropping legacy positional arguments
|
|
12
|
+
|
|
1
13
|
------------------
|
|
2
14
|
0.5.1 (2026-09-07)
|
|
3
15
|
------------------
|
data/README.md
CHANGED
|
@@ -179,6 +179,34 @@ By inheriting from `CLIClassTool::Common`, your action classes have access to a
|
|
|
179
179
|
|
|
180
180
|
---
|
|
181
181
|
|
|
182
|
+
## User Confirmation (`confirm`)
|
|
183
|
+
|
|
184
|
+
`CLIClassTool::Common` provides an inherited `confirm(opts, msg, confirm_opts = {})` helper method to prompt the user for interactive confirmation or automatically reply when `-y`/`--yes` or `-n`/`--no` CLI flags are set.
|
|
185
|
+
|
|
186
|
+
```ruby
|
|
187
|
+
# Basic confirmation
|
|
188
|
+
confirm(opts, "delete this branch")
|
|
189
|
+
# => Do you wish to delete this branch ? (y/n):
|
|
190
|
+
|
|
191
|
+
# Custom usage string printed in the prompt
|
|
192
|
+
confirm(opts, "apply changes", usage: "y/N")
|
|
193
|
+
# => Do you wish to apply changes ? (y/N):
|
|
194
|
+
|
|
195
|
+
# Custom allowed responses and custom usage
|
|
196
|
+
confirm(opts, "select conflict resolution", allowed_reps: ["y", "n", "a"], usage: "y/n/all")
|
|
197
|
+
# => Do you wish to select conflict resolution ? (y/n/all):
|
|
198
|
+
|
|
199
|
+
# Ignore CLI -y/--yes and -n/--no options to force interactive input
|
|
200
|
+
confirm(opts, "format the disk", ignored_default: true)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Supported Options:
|
|
204
|
+
- `:usage` (`String` or `Array<String>`): Custom usage string to display instead of `#{allowed_reps.join("/")}`.
|
|
205
|
+
- `:ignored_default` / `:ignore_default` (`Boolean`, default: `false`): If `true`, ignores `opts[:yn_default]` set by `--yes` or `--no`.
|
|
206
|
+
- `:allowed_reps` (`Array<String>`, default: `["y", "n"]`): List of acceptable user responses.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
182
210
|
## Dynamic Class Overrides (Addons)
|
|
183
211
|
|
|
184
212
|
`CLIClassTool` natively supports dynamic class overrides (addons). This allows projects to load repository-specific or custom subclasses that extend or override base action behaviors without modifying the core codebase.
|
|
@@ -393,4 +421,28 @@ rescue MyProjectError => e
|
|
|
393
421
|
end
|
|
394
422
|
```
|
|
395
423
|
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## String Colorization & Styling Extension
|
|
427
|
+
|
|
428
|
+
`CLIClassTool` extends the core Ruby `String` class with standard ANSI escape sequence methods for terminal colorization and formatting.
|
|
429
|
+
|
|
430
|
+
### 16-Color Palette Support
|
|
431
|
+
|
|
432
|
+
The following color methods are available on any string:
|
|
433
|
+
|
|
434
|
+
* **Standard Colors**: `.black`, `.red`, `.green`, `.brown` (alias `.yellow`), `.blue`, `.magenta`, `.cyan`, `.white`
|
|
435
|
+
* **High-Intensity / Bright Colors**: `.gray` (alias `.grey`), `.light_red`, `.light_green`, `.light_yellow`, `.light_blue`, `.light_magenta`, `.light_cyan`, `.light_white`
|
|
436
|
+
|
|
437
|
+
### Bold Mode and Method Chaining
|
|
438
|
+
|
|
439
|
+
You can style text as bold using the `.bold` method. All methods support seamless chaining/merging, meaning ANSI escape sequences are parsed and merged into a single escape code (e.g., `\e[1;31m`) rather than nested redundantly.
|
|
440
|
+
|
|
441
|
+
```ruby
|
|
442
|
+
puts "Success!".green # Green text
|
|
443
|
+
puts "Warning!".brown.bold # Bold brown (yellow) text
|
|
444
|
+
puts "Fatal Error!".bold.red # Bold red text
|
|
445
|
+
puts "System Message".bold # Bold text using default terminal color
|
|
396
446
|
```
|
|
447
|
+
|
|
448
|
+
These methods automatically check if `$stdout` is a TTY and safely fall back to standard, unformatted strings if output is piped or redirected (non-TTY mode).
|
|
@@ -77,14 +77,29 @@ module CLIClassTool
|
|
|
77
77
|
#
|
|
78
78
|
# @param opts [Hash] Options hash
|
|
79
79
|
# @param msg [String] Confirmation message
|
|
80
|
-
# @param
|
|
81
|
-
# @
|
|
80
|
+
# @param confirm_opts [Hash] Optional confirmation options
|
|
81
|
+
# @option confirm_opts [Boolean] :ignored_default (false) Ignore default yes/no options
|
|
82
|
+
# @option confirm_opts [Boolean] :ignore_default (false) Alias for :ignored_default
|
|
83
|
+
# @option confirm_opts [Array<String>] :allowed_reps (["y", "n"]) Allowed responses
|
|
84
|
+
# @option confirm_opts [String, Array<String>] :usage Custom usage string or list to display instead of allowed_reps.join("/")
|
|
82
85
|
# @return [String] User response
|
|
83
|
-
def confirm(opts, msg,
|
|
84
|
-
|
|
86
|
+
def confirm(opts, msg, confirm_opts = {})
|
|
87
|
+
raise ArgumentError, "confirm options must be a Hash" unless confirm_opts.is_a?(Hash)
|
|
88
|
+
|
|
89
|
+
conf_opts = confirm_opts.transform_keys(&:to_sym)
|
|
90
|
+
|
|
91
|
+
ignored_default = conf_opts[:ignored_default]
|
|
92
|
+
ignored_default = conf_opts[:ignore_default] if ignored_default.nil?
|
|
93
|
+
ignored_default = false if ignored_default.nil?
|
|
94
|
+
|
|
95
|
+
allowed_reps = (conf_opts[:allowed_reps] || [ "y", "n" ]).map(&:to_s)
|
|
96
|
+
usage = conf_opts[:usage]
|
|
97
|
+
usage_str = usage ? (usage.is_a?(Array) ? usage.join("/") : usage.to_s) : allowed_reps.join("/")
|
|
98
|
+
|
|
99
|
+
rep = nil
|
|
85
100
|
while allowed_reps.index(rep) == nil && rep != '' do
|
|
86
|
-
puts "Do you wish to #{msg} ? (#{
|
|
87
|
-
case (
|
|
101
|
+
puts "Do you wish to #{msg} ? (#{usage_str}): "
|
|
102
|
+
case (ignored_default == true ? nil : opts&.[](:yn_default))
|
|
88
103
|
when :no
|
|
89
104
|
puts "Auto-replying no due to --no option"
|
|
90
105
|
rep = 'n'
|
|
@@ -10,12 +10,33 @@ class String
|
|
|
10
10
|
def colorize(color_code)
|
|
11
11
|
@@is_a_tty = $stdout.isatty() if @@is_a_tty == nil
|
|
12
12
|
if @@is_a_tty then
|
|
13
|
-
|
|
13
|
+
if self =~ /\A\e\[([\d;]+)m(.*)\e\[0m\z/
|
|
14
|
+
codes = $1.split(';')
|
|
15
|
+
content = $2
|
|
16
|
+
new_codes = codes.dup
|
|
17
|
+
if color_code.to_i == 1
|
|
18
|
+
new_codes.unshift("1") unless new_codes.include?("1")
|
|
19
|
+
else
|
|
20
|
+
new_codes.reject! { |c| (30..37).include?(c.to_i) || (90..97).include?(c.to_i) }
|
|
21
|
+
new_codes << color_code.to_s
|
|
22
|
+
end
|
|
23
|
+
new_codes.uniq!
|
|
24
|
+
new_codes.sort_by! { |c| c.to_i }
|
|
25
|
+
return "\e[#{new_codes.join(';')}m#{content}\e[0m"
|
|
26
|
+
else
|
|
27
|
+
return "\e[#{color_code}m#{self}\e[0m"
|
|
28
|
+
end
|
|
14
29
|
else
|
|
15
30
|
return self
|
|
16
31
|
end
|
|
17
32
|
end
|
|
18
33
|
|
|
34
|
+
# Make the string black
|
|
35
|
+
# @return [String] Black string
|
|
36
|
+
def black
|
|
37
|
+
colorize(30)
|
|
38
|
+
end
|
|
39
|
+
|
|
19
40
|
# Make the string red
|
|
20
41
|
# @return [String] Red string
|
|
21
42
|
def red
|
|
@@ -34,6 +55,12 @@ class String
|
|
|
34
55
|
colorize(33)
|
|
35
56
|
end
|
|
36
57
|
|
|
58
|
+
# Make the string yellow
|
|
59
|
+
# @return [String] Yellow string
|
|
60
|
+
def yellow
|
|
61
|
+
colorize(33)
|
|
62
|
+
end
|
|
63
|
+
|
|
37
64
|
# Make the string blue
|
|
38
65
|
# @return [String] Blue string
|
|
39
66
|
def blue
|
|
@@ -45,4 +72,71 @@ class String
|
|
|
45
72
|
def magenta
|
|
46
73
|
colorize(35)
|
|
47
74
|
end
|
|
75
|
+
|
|
76
|
+
# Make the string cyan
|
|
77
|
+
# @return [String] Cyan string
|
|
78
|
+
def cyan
|
|
79
|
+
colorize(36)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Make the string white
|
|
83
|
+
# @return [String] White string
|
|
84
|
+
def white
|
|
85
|
+
colorize(37)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Make the string bold
|
|
89
|
+
# @return [String] Bold string
|
|
90
|
+
def bold
|
|
91
|
+
colorize(1)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Make the string gray/grey / light black
|
|
95
|
+
# @return [String] Gray string
|
|
96
|
+
def gray
|
|
97
|
+
colorize(90)
|
|
98
|
+
end
|
|
99
|
+
alias grey gray
|
|
100
|
+
|
|
101
|
+
# Make the string light red
|
|
102
|
+
# @return [String] Light red string
|
|
103
|
+
def light_red
|
|
104
|
+
colorize(91)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Make the string light green
|
|
108
|
+
# @return [String] Light green string
|
|
109
|
+
def light_green
|
|
110
|
+
colorize(92)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Make the string light yellow
|
|
114
|
+
# @return [String] Light yellow string
|
|
115
|
+
def light_yellow
|
|
116
|
+
colorize(93)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Make the string light blue
|
|
120
|
+
# @return [String] Light blue string
|
|
121
|
+
def light_blue
|
|
122
|
+
colorize(94)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Make the string light magenta
|
|
126
|
+
# @return [String] Light magenta string
|
|
127
|
+
def light_magenta
|
|
128
|
+
colorize(95)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Make the string light cyan
|
|
132
|
+
# @return [String] Light cyan string
|
|
133
|
+
def light_cyan
|
|
134
|
+
colorize(96)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Make the string light white
|
|
138
|
+
# @return [String] Light white string
|
|
139
|
+
def light_white
|
|
140
|
+
colorize(97)
|
|
141
|
+
end
|
|
48
142
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cli_class_tool
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nicolas Morey
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-09-
|
|
10
|
+
date: 2026-09-09 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rake
|