cli-mastermind 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e6d02e18aa42a0c2c627dcdc76f2989b30a89c222bfd183a177a186f54c9953
4
- data.tar.gz: 92541c8f669b777e89ba6c273b31f05ab3c51831653e4a2eacedd262d013ca10
3
+ metadata.gz: 6985ac774ff704f996e8e581b726bd5f04526040ea42b0d3e8a6b874d034c15e
4
+ data.tar.gz: d1b21815bf02e3c2466fd8ab946a4eb2470b9ea81b0e1ba3cd1e879614ae21c4
5
5
  SHA512:
6
- metadata.gz: fbea7750593009ed092d09055dd5ee120a1ea3ee442a9576adff043d0d7214bee30f825956c99645e0eac2df177d739d505fc4efbf42a9c8ce7105f158be19ca
7
- data.tar.gz: cc50ce47da3cc8aee137b85ae0c7bb04ca8060759a6e2a22999316ef3ee14e2a98ab5a36a41e354304158fad38c3651f642d425b912b765c525b70d689d06a7f
6
+ metadata.gz: 0e7b7f32271c7a7c309de2638b80197166e03519ccdda2a7779b86ab05c5be2e63d9e518993d178e6eeb190a5dbdb7ea52850aaa056ffcddc00a66fb034cb4ed
7
+ data.tar.gz: feccf940db4e9558056b6dc0afd5851c21051d72c7f4acf7ab167a128971b77285636f7aa14adc7c2078086be5054c72575e982d601357817a87765c5195562d
@@ -55,8 +55,8 @@ module CLI
55
55
  #
56
56
  # @see ArgParse.add_option
57
57
  #
58
- # @param args arguments passed directly to OptionParser#on
59
- # @param block [Proc] block passed as the handler for the above arguments
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
- attr_reader :extra_options
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<String>,Hash] the options to display
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.to_s) { default }
146
+ handler.option(default_text) { default }
123
147
 
124
148
  options.each do |(text, value)|
125
149
  handler.option(text) { value }
@@ -8,7 +8,7 @@ module CLI
8
8
  module VERSION
9
9
  RELEASE = 1
10
10
  MAJOR = 3
11
- MINOR = 0
11
+ MINOR = 1
12
12
  PATCH = nil
13
13
 
14
14
  STRING = [RELEASE, MAJOR, MINOR, PATCH].compact.join('.').freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli-mastermind
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hall