cli-mastermind 1.3.0 → 1.3.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 +4 -4
- data/lib/cli/mastermind.rb +2 -2
- data/lib/cli/mastermind/arg_parse.rb +3 -1
- data/lib/cli/mastermind/user_interface.rb +29 -5
- data/lib/cli/mastermind/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6985ac774ff704f996e8e581b726bd5f04526040ea42b0d3e8a6b874d034c15e
|
4
|
+
data.tar.gz: d1b21815bf02e3c2466fd8ab946a4eb2470b9ea81b0e1ba3cd1e879614ae21c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7b7f32271c7a7c309de2638b80197166e03519ccdda2a7779b86ab05c5be2e63d9e518993d178e6eeb190a5dbdb7ea52850aaa056ffcddc00a66fb034cb4ed
|
7
|
+
data.tar.gz: feccf940db4e9558056b6dc0afd5851c21051d72c7f4acf7ab167a128971b77285636f7aa14adc7c2078086be5054c72575e982d601357817a87765c5195562d
|
data/lib/cli/mastermind.rb
CHANGED
@@ -55,8 +55,8 @@ module CLI
|
|
55
55
|
#
|
56
56
|
# @see ArgParse.add_option
|
57
57
|
#
|
58
|
-
# @param args
|
59
|
-
# @param block
|
58
|
+
# @param args (see ArgParse.add_option)
|
59
|
+
# @param block (see ArgParse.add_option)
|
60
60
|
# @return [Void]
|
61
61
|
def add_argument(*args, &block)
|
62
62
|
ArgParse.add_option(*args, &block)
|
@@ -13,7 +13,9 @@ module CLI::Mastermind
|
|
13
13
|
class << self
|
14
14
|
# @see ArgParse.add_option
|
15
15
|
# @return [Array] a set of extra options added to the argument parser
|
16
|
-
|
16
|
+
def extra_options
|
17
|
+
@extra_options ||= []
|
18
|
+
end
|
17
19
|
|
18
20
|
# Adds arbitrary options to the argument parser.
|
19
21
|
#
|
@@ -70,9 +70,12 @@ module CLI::Mastermind::UserInterface
|
|
70
70
|
#
|
71
71
|
# @param question [String] the question to ask the user
|
72
72
|
# @param default [String] the default answer
|
73
|
+
# @params opts [Hash] Additional options passed to CLI::UI.ask
|
74
|
+
# @option opts [Boolean] :is_file (nil) Use file autocompletion (tab completion)
|
75
|
+
# @option opts [Boolean] :allow_empty (true) Allow the answer to be empty
|
73
76
|
# @return [String] the user's answer
|
74
|
-
def ask(question, default: nil)
|
75
|
-
CLI::UI.ask(question, default: default)
|
77
|
+
def ask(question, default: nil, **opts)
|
78
|
+
CLI::UI.ask(question, default: default, **opts)
|
76
79
|
end
|
77
80
|
|
78
81
|
# Ask the user a yes/no +question+
|
@@ -86,13 +89,16 @@ module CLI::Mastermind::UserInterface
|
|
86
89
|
|
87
90
|
# Display an interactive list of options for the user to select.
|
88
91
|
# If less than 2 options would be displayed, the default value is automatically
|
89
|
-
# returned
|
92
|
+
# returned unless +multiple:+ is +true+.
|
90
93
|
#
|
91
94
|
# @param question [String] The question to ask the user
|
92
|
-
# @param options [Array
|
95
|
+
# @param options [Array<#to_s>,Hash<#to_s>] the options to display
|
93
96
|
# @param default [String] The default value for this question. Assumed to exist
|
94
97
|
# within the given options.
|
95
98
|
# @param opts [Hash] additional options passed into +CLI::UI::Prompt.ask+.
|
99
|
+
# @option opts [Boolean] :multiple (false) Whether multiple selections should be made.
|
100
|
+
# @option opts [Boolean] :filter_ui (true) Enable option filtering
|
101
|
+
# @option opts [Boolean] :select_ui (true) Enable long-form option selection
|
96
102
|
#
|
97
103
|
# @see https://github.com/Shopify/cli-ui#interactive-prompts
|
98
104
|
def select(question, options:, default: options.first, **opts)
|
@@ -112,14 +118,32 @@ module CLI::Mastermind::UserInterface
|
|
112
118
|
default_text = options.invert[default]
|
113
119
|
end
|
114
120
|
|
121
|
+
default_text = default_text
|
122
|
+
|
115
123
|
# dup so that we don't change whatever was passed in
|
116
124
|
options.dup.tap { |o| o.delete(default_text) }
|
117
125
|
end
|
118
126
|
|
127
|
+
# Ensure all keys are strings for CLI::UI
|
128
|
+
default_text = default_text.to_s
|
129
|
+
options.transform_keys!(&:to_s)
|
130
|
+
|
131
|
+
# work around a bug in CLI::UI with multi-select and block invocation
|
132
|
+
if opts[:multiple]
|
133
|
+
# Put default at the beginning so it shows in the expected order
|
134
|
+
keys = [default_text] + options.keys
|
135
|
+
|
136
|
+
# Put default back into the options so it can be pulled out
|
137
|
+
options[default_text] = default
|
138
|
+
|
139
|
+
response = Array(CLI::UI::Prompt.ask(question, options: keys, **opts))
|
140
|
+
return response.map { |resp| options[resp] }
|
141
|
+
end
|
142
|
+
|
119
143
|
return default unless options.count > 0
|
120
144
|
|
121
145
|
CLI::UI::Prompt.ask(question, **opts) do |handler|
|
122
|
-
handler.option(default_text
|
146
|
+
handler.option(default_text) { default }
|
123
147
|
|
124
148
|
options.each do |(text, value)|
|
125
149
|
handler.option(text) { value }
|