Class: ShellOpts::Ast::Command

Inherits:
Node
  • Object
show all
Defined in:
lib/shellopts/ast/command.rb

Direct Known Subclasses

Program

Instance Attribute Summary collapse

Attributes inherited from Node

#grammar, #name

Instance Method Summary collapse

Methods inherited from Node

#key, #to_tuple

Constructor Details

#initialize(grammar, name) ⇒ Command

Returns a new instance of Command.



12
13
14
15
16
# File 'lib/shellopts/ast/command.rb', line 12

def initialize(grammar, name)
  super(grammar, name)
  @options = []
  @command = nil
end

Instance Attribute Details

#commandObject

Optional sub-command (Ast::Command). Initially nil but assigned by the parser



10
11
12
# File 'lib/shellopts/ast/command.rb', line 10

def command
  @command
end

#optionsObject (readonly)

Array of options (Ast::Option). Initially empty but filled out by the parser



6
7
8
# File 'lib/shellopts/ast/command.rb', line 6

def options
  @options
end

Instance Method Details

#dump(&block) ⇒ Object

:nocov:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shellopts/ast/command.rb', line 24

def dump(&block)
  super {
    yield if block_given?
    puts "options:"
    indent { options.each { |opt| opt.dump } }
    print "command:"
    if command
      puts
      indent { command.dump }
    else
      puts "nil"
    end
  }
end

#valuesObject

Array of option or command tuples



19
20
21
# File 'lib/shellopts/ast/command.rb', line 19

def values
  (options + (Array(command || []))).map { |node| node.to_tuple }
end