OptParser
Mojo struct 🡭
OptParser
@memory_only
struct OptParser[OptParser] will try to parse your long-form CLI options.
Fields
- options (
Dict[String, OptConfig]): The options this will attempt to parse. - program_description (
String): The description of the program, to be used in the help message. - program_name (
String): Your programs name, to be used in the help message. - min_num_args_expected (
Optional[Int]): Whether or not to expect any program args, and if so, at least (>=) how many. - args_help_msg (
String): Help message for arguments.
Implemented traits
AnyType, Copyable, Deinitable, Movable
Methods
➕ ➖__init__
def __init__(out self, *, name: String, description: String = "")Details
Args:
- name (
String) - description (
String) - self (
Self)
Returns:
Self
Raises:
expect_at_least_n_args
def expect_at_least_n_args(mut self, n: Int, args_help_msg: String = "")The minimum number of args to expect.
len(args) >= min_num_args_expected
If not set, args are not checked.
Args:
- self (
Self) - n (
Int) - args_help_msg (
String)
add_opt
def add_opt(mut self, var arg: OptConfig)Add an [
Args:OptConfig].
- self (
Self) - arg (
OptConfig)
help_msg
def help_msg(self) -> StringGet the help message string based on the currently added options.
Args:
- self (
Self)
Returns:
String
parse_sys_args
def parse_sys_args(mut self) -> ParsedOptsParse the arguments from
Args:sys.argv().
- self (
Self)
Returns:
ParsedOpts
Raises:
parse_args
def parse_args(self, args: List[String]) -> ParsedOptsParse the arguments passed in via
Args:args.
- self (
Self) - args (
List[String])
Returns:
ParsedOpts
Raises: