cli_class_tool 0.5.1 → 1.0.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 +6 -0
- data/README.md +28 -0
- data/lib/cli_class_tool/common.rb +21 -6
- 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: 26a3ec0d29127e28be8a7f8d5cdeccf36dbe19fa2ef06d7cd11f82caf4963dd8
|
|
4
|
+
data.tar.gz: 8a210596d6735be7f3a5f41df93b43c023b46315055f5c5622c833e0de743da8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72e72cbdcbaf6eac25b87f57ae63f628e4ea28b7e7093d7473fc5324751b459de25a6f49986c10ae7ded00390f57b0534c502e49a80471340d9cf54bd22600fb
|
|
7
|
+
data.tar.gz: 18df3b843eae58f00e46eddcc24b3c38183c57dfcf835a57bc21f0ec12ecca967d1e4712c100810b80c4e4dba3fa2b6f1c2de4ceb5e6dda49ea08e48b5ce8f4d
|
data/CHANGELOG
CHANGED
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.
|
|
@@ -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'
|
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: 0.
|
|
4
|
+
version: 1.0.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
|