Search results

There are no results.

std.optparse.Matches

class pub Matches

A type containing the parsed options and any remaining arguments.

Fields

remaining

let pub @remaining: Array[String]

The remaining/unparsed arguments.

Instance methods

contains?

Show source code
Hide source code
fn pub contains?(name: String) -> Bool {
  @options.contains?(name)
}
fn pub contains?(name: String) -> Bool

Returns true if the given option is given.

The name argument can be either the short or long name of an option.

Examples

import optparse.Options

let opts = Options.new

opts.flag('h', 'help', 'Show this help message')

let matches = opts.parse(['-h']).unwrap

matches.contains?('h')    # => true
matches.contains?('help') # => true

value

Show source code
Hide source code
fn pub value(name: String) -> Option[String] {
  @options.opt(name).then(fn (v) { v.opt(0) }).then(fn (v) { v.as_string })
}
fn pub value(name: String) -> Option[String]

Returns a single value for the option, if any.

The name argument can be either the short or long name of an option.

If the option doesn't accept any arguments, this method returns None. If the option has multiple arguments assigned, this method returns the first argument.

Examples

import optparse.Options

let opts = Options.new

opts.single('c', 'config', 'PATH', 'Use a custom configuration file')

let matches = opts.parse(['-c', 'foo.json']).unwrap

matches.value('c')      # => Option.Some('foo.json')
matches.value('config') # => Option.Some('foo.json')

values

Show source code
Hide source code
fn pub values(name: String) -> Array[String] {
  match @options.opt(name) {
    case Some(vals) -> vals.iter.select_map(fn (v) { v.as_string }).to_array
    case _ -> []
  }
}
fn pub values(name: String) -> Array[String]

Returns the values for the option.

If no values are present or the option doesn't take any arguments, an empty Array is returned.

Examples

import optparse.Options

let opts = Options.new

opts.multiple('i', 'include', 'PATH', 'Include the given directory')

let matches = opts.parse(['-i', 'test', '-i', 'src']).unwrap

matches.values('i')       # => ['test', 'src']
matches.values('include') # => ['test', 'src']