Class: Como::ArgsParseState

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

Overview

Command argument parsing state.

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ ArgsParseState

Create parse state.

Parameters:

  • list (Array<String>)

    List of Command Line Arguments (default: ARGV).



2121
2122
2123
2124
# File 'lib/como.rb', line 2121

def initialize( list )
    set( list )
    @idx = 0
end

Instance Method Details

#done?Boolean

Parser at argument list end?

Returns:

  • (Boolean)


2157
2158
2159
# File 'lib/como.rb', line 2157

def done?
    @idx >= @list.length
end

#get(idx = @idx) ⇒ Object

Get current argument.



2142
2143
2144
# File 'lib/como.rb', line 2142

def get( idx = @idx )
    @args[ idx ]
end

#isOpt(str = get) ⇒ Object

Test whether str is an option.



2163
2164
2165
# File 'lib/como.rb', line 2163

def isOpt( str = get )
    str[0..0] == "-"
end

#isOptTerm(str = get) ⇒ Object

Test whether str is an option list terminator.



2168
2169
2170
# File 'lib/como.rb', line 2168

def isOptTerm( str = get )
    str == "--"
end

#last(idx = @idx) ⇒ Object

Get last argument.



2147
2148
2149
# File 'lib/como.rb', line 2147

def last( idx = @idx )
    idx == ( @args.length-1 )
end

#nextObject

Step to next argument.



2132
2133
2134
# File 'lib/como.rb', line 2132

def next
    @idx += 1
end

#prevObject

Step to previous argument.



2137
2138
2139
# File 'lib/como.rb', line 2137

def prev
    @idx -= 1
end

#rest(idx = @idx) ⇒ Object

Get rest of the arguments.



2152
2153
2154
# File 'lib/como.rb', line 2152

def rest( idx = @idx )
    @args[ idx..-1 ]
end

#set(list) ⇒ Object

Set list of arguments.



2127
2128
2129
# File 'lib/como.rb', line 2127

def set( list )
    @args = list
end

#toValue(str = get) ⇒ Object

Format value string if escaped.



2173
2174
2175
2176
2177
2178
2179
# File 'lib/como.rb', line 2173

def toValue( str = get )
    if str[0..0] == "\\"
        str[1..-1]
    else
        str
    end
end