Module: Thor::Completion::Bash::ArgumentMixin

Defined in:
lib/thor/completion/bash/argument_mixin.rb

Overview

Methods mixed in to Argument.

Instance Method Summary collapse

Instance Method Details

#bash_complete(request:, klass:) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/thor/completion/bash/argument_mixin.rb', line 42

def bash_complete request:, klass:
  # logger.level = :trace

  logger.trace "ENTERING #{ self.class }##{ __method__ }",
    name: name,
    complete: complete,
    request: request,
    klass: klass

  unless complete
    return [].tap { |results|
      logger.trace "No `#complete` proc to call",
        results: results
    }
  end

  values = case complete.arity
  when 0
    complete.call
  else
    complete.call request: request, klass: klass, command: self
  end

  logger.trace "Got values", values: values

  values.
    select { |value| value.start_with? request.cur }.
    tap { |results|
      logger.trace "Selected values for argument #{ name }",
        results: results
    }
end