Skip to content

Options::apply should permit returning an error #112

@BenWiederhake

Description

@BenWiederhake

This is a bit ugly, but sometimes the error while parsing an argument seems to take precedence over anything (including other errors) that might be encountered later:

$ date -R -R --help
date: multiple output formats specified
[$? = 1]

See also uutils/coreutils#4254 (comment) for further examples.

I propose changing the interface to:

pub trait Options<Arg: Arguments>: Sized {
    /// Apply a single argument to the options.
    fn apply(&mut self, arg: Arg) -> Result<(), Error>;

    // Rest basically unchanged; the default `parse` impl would simply call `parse()?` instead.
}

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions