cli
OptParser

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, ExplicitlyCopyable, Movable, UnknownDestructibility

Methods

 

__init__

fn __init__(out self, *, name: String, description: String = "")

Details Args:

  • name (String)
  • description (String)
  • self (Self)

Returns:

Self

Raises:

expect_at_least_n_args

fn 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

fn add_opt(mut self, var arg: OptConfig)

Add an [OptConfig]. Args:

  • self (Self)
  • arg (OptConfig)

help_msg

fn help_msg(self) -> String

Get the help message string based on the currently added options. Args:

  • self (Self)

Returns:

String

parse_sys_args

fn parse_sys_args(mut self) -> ParsedOpts

Parse the arguments from sys.argv(). Args:

  • self (Self)

Returns:

ParsedOpts

Raises:

parse_args

fn parse_args(self, args: List[String]) -> ParsedOpts

Parse the arguments passed in via args. Args:

  • self (Self)
  • args (List)

Returns:

ParsedOpts

Raises: