Skip to content

Conversation

@Hi-Angel
Copy link
Contributor

Refactoring aside, this fixes the problem when --color-numbers was followed by another option, such as for example diffr --line-numbers --help. Such combination of parameters would cause an error before this PR.

@Hi-Angel
Copy link
Contributor Author

upd: didn't know there are single-dash options like -h, added their handling as well

src/cli_args.rs Outdated
fn parse_line_number_style<'a>(
config: &mut AppConfig,
value: Option<&'a str>,
value: Option<&'a String>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feel weird that you have to change this type.
what you could do is change the call site to maybe_line_number_style.map(|s| &s[..])

Copy link
Contributor Author

@Hi-Angel Hi-Angel Jan 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like overcomplicating, but I'll do if you really want. I'll note in the commit message that I was asked by the maintainer to do that if you're okay with that, because I personally would not like that.

true
}

fn debug(config: &mut AppConfig, args: &mut Peekable<impl Iterator<Item = String>>) -> bool {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep the signatures of all the arguments handlers the same (debug, html, line_numbers...) even if the functions themselves look dull.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd, but you are the boss. Do you want me to leave that as is with the warning of args being unused, or is there any way to silence it? Like a pragma or what analog does Rust have

@mookid
Copy link
Owner

mookid commented Jan 21, 2023

please consider adding a test if you fix a bug to avoid regression.
thanks!

There is no reason for config-handling hooks (like color(), html(), etc)
to peek at the value that caused them to be called. So call next()
before calling the hooks.

That allows to simplify the code and remove some args, but we do not do
that per mookid's review, who asked to leave arguments of the hooks to
be the same even if some of the functions do not actually use arguments.
@Hi-Angel
Copy link
Contributor Author

Anyway, done.

So for example, calling:

    diffr --line-numbers --help

was resulting in error before this commit:

    unexpected line number style: got '--help', expected aligned|compact

Works now.
The weird call `maybe_line_number_style.map()` is implemented by
mookid's review who would not like just changing the
parse_line_number_style() argument type.
@Hi-Angel
Copy link
Contributor Author

Note that there are two warnings now. I'm not sure I'm a fan of that kind of consistency, but you are the maintainer, so here it is.

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 this pull request may close these issues.

2 participants