Class: RHC::AutoCompleteBindings

Inherits:
Object
  • Object
show all
Defined in:
lib/rhc/autocomplete.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ AutoCompleteBindings

Returns a new instance of AutoCompleteBindings.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rhc/autocomplete.rb', line 23

def initialize(data)
  @commands = {}
  @top_level_commands = []

  data.runner.commands.each_pair do |name, cmd|
    next if cmd.summary.nil?
    next if cmd.deprecated(name)

    if cmd.root?
      if cmd.name == name
        @top_level_commands << name
      end
    else
      @top_level_commands << name if name == cmd.name
      commands = name.split ' '
      action = commands.pop
      id = commands.join(' ')
      v = @commands[id] || {:actions => [], :switches => []}
      v[:actions] << action unless id == '' && name != cmd.name
      @commands[id] = v
    end

    v = @commands[name.to_s] || {:actions => [], :switches => []}
    v[:switches].concat(cmd.options.map do |o| 
      if o[:switches] 
        s = o[:switches][-1].split(' ')[0]
        if m = /--\[no-\](.+)/.match(s)
          s = ["--#{m[1]}", "--no-#{m[1]}"]
        else
          s
        end
      end
    end.flatten.compact.sort)
    @commands[name.to_s] = v
  end
  @commands.delete('')
  @commands = @commands.to_a.sort{ |a,b| a[0] <=> b[0] }

  @top_level_commands.sort!

  @global_options = data.runner.options.map{ |o| o[:switches][-1].split(' ')[0] }.sort
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



21
22
23
# File 'lib/rhc/autocomplete.rb', line 21

def commands
  @commands
end

#global_optionsObject (readonly)

Returns the value of attribute global_options.



21
22
23
# File 'lib/rhc/autocomplete.rb', line 21

def global_options
  @global_options
end

#top_level_commandsObject (readonly)

Returns the value of attribute top_level_commands.



21
22
23
# File 'lib/rhc/autocomplete.rb', line 21

def top_level_commands
  @top_level_commands
end