ParsedOpts

Mojo struct 🡭

ParsedOpts

@memory_only
struct ParsedOpts

The parsed CLI options. Access your values with ParsedOpts.get_string(), ParsedOpts.get_int(), etc.

Access CLI arguments from ParsedOpts.args. Get the help message with ParsedOpts.get_help_message.

Note that there is an automatic help flag added to your options, it can be overridden by another option with that same name. The input args are first scanned for “–help” and if that is found the parser will exit early, returning the parsed value of the “–help” flag (or option if you have overridden it). It is up to the user to check for the “help” option being set and print the help message.

Fields

  • options (Dict[String, OptValue])
  • args (List[String])
  • help_msg (String)

Implemented traits

AnyType, Copyable, Deinitable, Movable

Methods

 

__init__

def __init__(out self, var help_msg: String = "")

DetailsArgs:

  • help_msg (String)
  • self (Self)

Returns:

Self

get_help_message

def get_help_message(ref self) -> Pointer[String, origin_of(self.help_msg)]

Get a nicely formatted help string.Args:

  • self (Self)

Returns:

Pointer[String, origin_of(self.help_msg)]

get_string

def get_string(self, key: String) -> String

Try to get the option specified with the given key as a String.This will raise if the key is not found, or if the type of the option doesn’t match asked-for type.

Args:

  • self (Self)
  • key (String)

Returns:

String

Raises:

get_int

def get_int(self, key: String) -> Int

Try to get the option specified with the given key as an Int.This will raise if the key is not found, or if the type of the option doesn’t match asked-for type.

Args:

  • self (Self)
  • key (String)

Returns:

Int

Raises:

get_float

def get_float(self, key: String) -> Float64

Try to get the option specified with the given key as a Float64.This will raise if the key is not found, or if the type of the option doesn’t match asked-for type.

Args:

  • self (Self)
  • key (String)

Returns:

Float64

Raises:

get_bool

def get_bool(self, key: String) -> Bool

Try to get the option specified with the given key as a Bool.This will raise if the key is not found, or if the type of the option doesn’t match asked-for type.

Args:

  • self (Self)
  • key (String)

Returns:

Bool

Raises: