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).



2160
2161
2162
2163
# File 'lib/como.rb', line 2160

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

Instance Method Details

#done?Boolean

Parser at argument list end?

Returns:

  • (Boolean)


2196
2197
2198
# File 'lib/como.rb', line 2196

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

#get(idx = @idx) ⇒ Object

Get current argument.



2181
2182
2183
# File 'lib/como.rb', line 2181

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

#isOpt(str = get) ⇒ Object

Test whether str is an option.



2201
2202
2203
# File 'lib/como.rb', line 2201

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

#isOptTerm(str = get) ⇒ Object

Test whether str is an option list terminator.



2206
2207
2208
# File 'lib/como.rb', line 2206

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

#last(idx = @idx) ⇒ Object

Get last argument.



2186
2187
2188
# File 'lib/como.rb', line 2186

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

#nextObject

Step to next argument.



2171
2172
2173
# File 'lib/como.rb', line 2171

def next
    @idx += 1
end

#prevObject

Step to previous argument.



2176
2177
2178
# File 'lib/como.rb', line 2176

def prev
    @idx -= 1
end

#rest(idx = @idx) ⇒ Object

Get rest of the arguments.



2191
2192
2193
# File 'lib/como.rb', line 2191

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

#set(list) ⇒ Object

Set list of arguments.



2166
2167
2168
# File 'lib/como.rb', line 2166

def set( list )
    @args = list
end

#toValue(str = get) ⇒ Object

Format value string if escaped.



2211
2212
2213
2214
2215
2216
2217
# File 'lib/como.rb', line 2211

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