[go: up one dir, main page]

Options

Trait Options 

Source
pub trait Options {
Show 14 methods // Required methods fn parse<S: AsRef<str>>(parser: &mut Parser<'_, S>) -> Result<Self, Error> where Self: Sized; fn command(&self) -> Option<&dyn Options>; fn parse_command<S: AsRef<str>>( name: &str, parser: &mut Parser<'_, S>, ) -> Result<Self, Error> where Self: Sized; fn usage() -> &'static str where Self: Sized; fn self_usage(&self) -> &'static str; fn command_usage(command: &str) -> Option<&'static str> where Self: Sized; fn command_list() -> Option<&'static str> where Self: Sized; fn self_command_list(&self) -> Option<&'static str>; // Provided methods fn command_name(&self) -> Option<&'static str> { ... } fn help_requested(&self) -> bool { ... } fn parse_args<S: AsRef<str>>( args: &[S], style: ParsingStyle, ) -> Result<Self, Error> where Self: Sized { ... } fn parse_args_or_exit(style: ParsingStyle) -> Self where Self: Sized { ... } fn parse_args_default_or_exit() -> Self where Self: Sized { ... } fn parse_args_default<S: AsRef<str>>(args: &[S]) -> Result<Self, Error> where Self: Sized { ... }
}
Expand description

Implements a set of options parsed from command line arguments.

An implementation of this trait can be generated with #[derive(Options)].

Required Methods§

Source

fn parse<S: AsRef<str>>(parser: &mut Parser<'_, S>) -> Result<Self, Error>
where Self: Sized,

Parses arguments until the given parser is exhausted or until an error is encountered.

Source

fn command(&self) -> Option<&dyn Options>

Returns the subcommand instance, if present.

This method must never return self or otherwise return a &dyn Options instance which would create a cycle. Doing so may cause other methods or gumdrop functions to loop infinitely or overflow the runtime stack.

Source

fn parse_command<S: AsRef<str>>( name: &str, parser: &mut Parser<'_, S>, ) -> Result<Self, Error>
where Self: Sized,

Parses options for the named command.

Source

fn usage() -> &'static str
where Self: Sized,

Returns a string showing usage and help for each supported option.

Option descriptions are separated by newlines. The returned string should not end with a newline.

Source

fn self_usage(&self) -> &'static str

Returns a string showing usage and help for this options instance.

In contrast to usage, this method will return usage for a subcommand, if one is selected.

Option descriptions are separated by newlines. The returned string should not end with a newline.

Source

fn command_usage(command: &str) -> Option<&'static str>
where Self: Sized,

Returns a usage string for the named command.

If the named command does not exist, None is returned.

Command descriptions are separated by newlines. The returned string should not end with a newline.

Source

fn command_list() -> Option<&'static str>
where Self: Sized,

Returns a string listing available commands and help text.

Commands are separated by newlines. The string should not end with a newline.

For enum types with derive(Options), this is the same as usage.

For struct types containing a field marked #[options(command)], usage is called on the command type.

Source

fn self_command_list(&self) -> Option<&'static str>

Returns a listing of available commands and help text.

In contrast to usage, this method will return command list for a subcommand, if one is selected.

Commands are separated by newlines. The string should not end with a newline.

Provided Methods§

Source

fn command_name(&self) -> Option<&'static str>

Returns the name of a parsed command, if present.

This is implemented by derive(Options) in one of two ways:

  • For struct types, if the type contains a field marked #[options(command)], this method is called on that value. Otherwise, None is returned.
  • For enum types, the name corresponding to the variant is returned.
Source

fn help_requested(&self) -> bool

Returns whether the user supplied a “help” option to request usage information about the program or any contained subcommands.

The default implementation returns false.

Source

fn parse_args<S: AsRef<str>>( args: &[S], style: ParsingStyle, ) -> Result<Self, Error>
where Self: Sized,

Parses arguments received from the command line.

The first argument (the program name) should be omitted.

Source

fn parse_args_or_exit(style: ParsingStyle) -> Self
where Self: Sized,

Parses arguments from the environment.

If an error is encountered, the error is printed to stderr and the process will exit with status code 2.

If the user supplies a help option, option usage will be printed to stderr and the process will exit with status code 0.

Otherwise, the parsed options are returned.

Source

fn parse_args_default_or_exit() -> Self
where Self: Sized,

Parses arguments from the environment, using the default parsing style.

If an error is encountered, the error is printed to stderr and the process will exit with status code 2.

If the user supplies a help option, option usage will be printed to stderr and the process will exit with status code 0.

Otherwise, the parsed options are returned.

Source

fn parse_args_default<S: AsRef<str>>(args: &[S]) -> Result<Self, Error>
where Self: Sized,

Parses arguments received from the command line, using the default parsing style.

The first argument (the program name) should be omitted.

Implementors§