Class: DocoptCompgen::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/docopt_compgen/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
12
# File 'lib/docopt_compgen/node.rb', line 7

def initialize(parent = nil)
    @parent = parent
    @subcommands = {}
    @options = []
    @arguments = []
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



3
4
5
# File 'lib/docopt_compgen/node.rb', line 3

def arguments
  @arguments
end

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/docopt_compgen/node.rb', line 5

def parent
  @parent
end

#subcommandsObject (readonly)

Returns the value of attribute subcommands.



4
5
6
# File 'lib/docopt_compgen/node.rb', line 4

def subcommands
  @subcommands
end

Instance Method Details

#add_argument(argument) ⇒ Object



14
15
16
# File 'lib/docopt_compgen/node.rb', line 14

def add_argument(argument)
    @arguments << argument
end

#add_option(option) ⇒ Object



18
19
20
# File 'lib/docopt_compgen/node.rb', line 18

def add_option(option)
    @options << option
end

#add_subcommand(name) ⇒ Object



30
31
32
33
34
35
# File 'lib/docopt_compgen/node.rb', line 30

def add_subcommand(name)
    if @subcommands[name].nil?
        @subcommands[name] = Node.new(self)
    end
    @subcommands[name]
end

#optionsObject



22
23
24
25
26
27
28
# File 'lib/docopt_compgen/node.rb', line 22

def options
    options = @options
    if @parent
        options += @parent.options
    end
    options.uniq
end