Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options::apply should permit returning an error #112

Open
BenWiederhake opened this issue Mar 29, 2024 · 1 comment · May be fixed by #113
Open

Options::apply should permit returning an error #112

BenWiederhake opened this issue Mar 29, 2024 · 1 comment · May be fixed by #113

Comments

@BenWiederhake
Copy link
Contributor

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?

@tertsdiepraam
Copy link
Member

I've tried to hold of on this and figure out a system where all errors are generated by the parser and the Value trait, but I don't see any way to model this behaviour with that (if even I think that printing --help is the more "correct" thing to do). So, yeah, this is probably a good idea!

By the way, did you get my discord message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants