Sha256: 5282a5a83f4c0f56257cef6906beb23915b9c645b3d9bc626bc8f2013899748c

Contents?: true

Size: 937 Bytes

Versions: 13

Compression:

Stored size: 937 Bytes

Contents

module ShellOpts
  module Ast
    class Command < Node
      # Array of options (Ast::Option). Initially empty but filled out by the
      # parser
      attr_reader :options

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

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

      # Array of option or command tuples
      def values
        (options + (Array(command || []))).map { |node| node.to_tuple }
      end

      # :nocov:
      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
      # :nocov:
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shellopts-1.0.1 lib/shellopts/ast/command.rb
shellopts-2.0.0.pre.4 lib/shellopts/ast/command.rb
shellopts-2.0.0.pre.3 lib/shellopts/ast/command.rb
shellopts-2.0.0.pre.2 lib/shellopts/ast/command.rb
shellopts-2.0.0.pre.1 lib/shellopts/ast/command.rb
shellopts-1.0.0 lib/shellopts/ast/command.rb
shellopts-0.9.7 lib/shellopts/ast/command.rb
shellopts-0.9.6 lib/shellopts/ast/command.rb
shellopts-0.9.5 lib/shellopts/ast/command.rb
shellopts-0.9.4 lib/shellopts/ast/command.rb
shellopts-0.9.3 lib/shellopts/ast/command.rb
shellopts-0.9.2 lib/shellopts/ast/command.rb
shellopts-0.9.1 lib/shellopts/ast/command.rb