Method: HighLine#shell_style_lambda

Defined in:
lib/highline.rb

#shell_style_lambda(menu) ⇒ lambda

Convenience method to craft a lambda suitable for beind used in autocompletion operations by #choose

Returns:

  • (lambda)

    lambda to be used in autocompletion operations



292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/highline.rb', line 292

def shell_style_lambda(menu)
  lambda do |command| # shell-style selection
    first_word = command.to_s.split.first || ""

    options = menu.options
    options.extend(OptionParser::Completion)
    answer = options.complete(first_word)

    raise Question::NoAutoCompleteMatch unless answer

    [answer.last, command.sub(/^\s*#{first_word}\s*/, "")]
  end
end