tokei icon indicating copy to clipboard operation
tokei copied to clipboard

[bugfix] fix panics from `clap` internal type casting

Open JackDyre opened this issue 1 year ago • 2 comments

Resolves #1236

Any CLI flags that are constructed with the .value_parser(["slice", "of", "possible", "values"]) would cause clap to panic due to a type casting error whenever parsed into any type other than String, (even &str).

The best solution is to parse to a String and map it to parse it further. The value_parser!() macro is more concise and allows clap to parse to the type specified, but you lose the error message that tells the user the possible values to pass to the flag.

Tests pass

A follow-up PR that adds test coverage to the CLI flags might be a good idea so this doesn't happen again.

JackDyre avatar Feb 20 '25 05:02 JackDyre

Oops I didn't notice until now that I did all of this just to be a duplicate of #1233.

That said I believe my PR is more robust as it handles panics in more than just the --num-format flag, and I believe the other PR has a logic error since it calls .ok() on the parse result and doesn't exit if it fails to parse the flag value

JackDyre avatar Feb 20 '25 05:02 JackDyre

Oops I just noticed this PR is also a duplicate of #1209. Smh I need to do better investiagtion.

I still believe my implementation is better as per my comment about value_parser!() and fixing the other affect CLI flags

JackDyre avatar Feb 20 '25 16:02 JackDyre