Class: Kube::Ctl::CommandTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/kube/ctl/command_tree/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, options: [], inherited_options: [], usage: nil) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
12
13
# File 'lib/kube/ctl/command_tree/node.rb', line 7

def initialize(name:, options: [], inherited_options: [], usage: nil)
  @name = name
  @options = index_flags(options)
  @inherited_options = index_flags(inherited_options)
  @subcommands = {}
  @usage = usage
end

Instance Attribute Details

#inherited_optionsObject (readonly)

Returns the value of attribute inherited_options.



5
6
7
# File 'lib/kube/ctl/command_tree/node.rb', line 5

def inherited_options
  @inherited_options
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/kube/ctl/command_tree/node.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/kube/ctl/command_tree/node.rb', line 5

def options
  @options
end

#subcommandsObject (readonly)

Returns the value of attribute subcommands.



5
6
7
# File 'lib/kube/ctl/command_tree/node.rb', line 5

def subcommands
  @subcommands
end

#usageObject (readonly)

Returns the value of attribute usage.



5
6
7
# File 'lib/kube/ctl/command_tree/node.rb', line 5

def usage
  @usage
end

Instance Method Details

#add_subcommand(node) ⇒ Object



15
16
17
# File 'lib/kube/ctl/command_tree/node.rb', line 15

def add_subcommand(node)
  @subcommands[node.name] = node
end

#find_subcommand(token) ⇒ Object



19
20
21
# File 'lib/kube/ctl/command_tree/node.rb', line 19

def find_subcommand(token)
  @subcommands[token]
end

#known_flagsObject

Merge own + inherited flags. Inherited is “inherited from ancestors”, in kubectl’s YAML it’s already flattened per command.



25
26
27
# File 'lib/kube/ctl/command_tree/node.rb', line 25

def known_flags
  @options.merge(@inherited_options)
end