Class Clio::Usage::Interface
In: lib/clio/usage/interface.rb
Parent: Object

Command Interface (toplevel signature)

The end result provide by Usage::Parser#parse. This class consists of an array of command signatures and parse errors.

Methods

[]   arguments   command   commands   method_missing   new   options   parameters   switches   to_a   valid?  

External Aliases

errors -> parse_errors

Attributes

errors  [R] 
signatures  [R] 

Public Class methods

[Source]

# File lib/clio/usage/interface.rb, line 19
      def initialize(signatures=[], errors=[])
        @signatures = signatures
        @errors     = errors
      end

Public Instance methods

Index on each subcommand, with 0 being the toplevel command.

[Source]

# File lib/clio/usage/interface.rb, line 88
      def [](i)
        @signatures[i]
      end

[Source]

# File lib/clio/usage/interface.rb, line 56
      def arguments
        #parse unless parsed?
        @arguments ||= (
          m = []
          @signatures.each do |s|
            m.concat(s.arguments)
          end
          m
        )
      end

TODO: Join by what character?

[Source]

# File lib/clio/usage/interface.rb, line 25
      def command
        return nil if commands.empty?
        return commands.join(' ')
      end

[Source]

# File lib/clio/usage/interface.rb, line 31
      def commands
        #parse unless parsed?
        @commands ||= (
          a = []
          @signatures[1..-1].each do |s|
            a << s.command.to_s
          end
          a
        )
      end

[Source]

# File lib/clio/usage/interface.rb, line 99
      def method_missing(s, *a)
        s = s.to_s
        case s
        #when /[=]$/
        #  n = s.chomp('=')
        #  usage.option(n).type(*a)
        #  #parser.parse
        #  res = parser.options[n.to_sym]
        #when /[!]$/
        #  n = s.chomp('!')
        #  res = parser.parse
        when /[?]$/
          options[s.chomp('?').to_sym]
        else
          options[s.to_sym]
        end
      end

[Source]

# File lib/clio/usage/interface.rb, line 43
      def options
        #parse unless parsed?
        @options ||= (
          h = {}
          @signatures.each do |s|
            h.merge!(s.options)
          end
          h
        )
      end

Return parameters array of [*arguments, options]

[Source]

# File lib/clio/usage/interface.rb, line 68
      def parameters
        arguments + [options]
      end
switches()

Alias for options

[Source]

# File lib/clio/usage/interface.rb, line 93
      def to_a
        #parse unless parsed?
        @signatures.collect{ |s| s.to_a }
      end

Were the commandline arguments valid? This simply checks to see if there were any parse errors.

[Source]

# File lib/clio/usage/interface.rb, line 82
      def valid?
        #parse unless @parsed
        errors.empty?
      end

[Validate]