Class: GLI::Commands::HelpModules::HelpCompletionFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/gli/commands/help_modules/help_completion_format.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, command_finder, args) ⇒ HelpCompletionFormat

Returns a new instance of HelpCompletionFormat.



5
6
7
8
9
10
# File 'lib/gli/commands/help_modules/help_completion_format.rb', line 5

def initialize(app,command_finder,args)
  @app = app
  @command_finder = command_finder
  @command_finder.squelch_stderr = true
  @args = args
end

Instance Method Details

#formatObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gli/commands/help_modules/help_completion_format.rb', line 12

def format
  name = @args.shift

  base = @command_finder.find_command(name)
  base = @command_finder.last_found_command if base.nil?
  base = @app if base.nil?

  prefix_to_match = @command_finder.last_unknown_command

  base.commands.values.map { |command|
    [command.name,command.aliases]
  }.flatten.compact.map(&:to_s).sort.select { |command_name|
    prefix_to_match.nil? || command_name =~ /^#{prefix_to_match}/
  }.join("\n")
end