Class: Clamp::Completion::ParamsSatisfiedHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/clamp/completion/fish_generator.rb

Overview

Generates a fish function that checks whether required parameters have been provided before offering subcommand completions.

Instance Method Summary collapse

Constructor Details

#initialize(executable_name, path, required_count) ⇒ ParamsSatisfiedHelper

Returns a new instance of ParamsSatisfiedHelper.



157
158
159
160
161
# File 'lib/clamp/completion/fish_generator.rb', line 157

def initialize(executable_name, path, required_count)
  @executable_name = executable_name
  @path = path
  @required_count = required_count
end

Instance Method Details

#function_name ⇒ Object



163
164
165
166
167
# File 'lib/clamp/completion/fish_generator.rb', line 163

def function_name
  parts = [@executable_name]
  @path.each { |sub| parts << sub.names.first }
  "_clamp_complete_#{parts.join('_')}_params_satisfied"
end

#to_s ⇒ Object



169
170
171
172
173
174
175
176
177
178
# File 'lib/clamp/completion/fish_generator.rb', line 169

def to_s
  lines = ["function #{function_name}", "    set -l tokens (commandline -opc)", "    set -l positional 0"]
  if @path.empty?
    count_positional_root(lines)
  else
    count_positional_nested(lines)
  end
  lines.push("    test $positional -ge #{@required_count}", "end")
  lines.join("\n")
end