Navigation Menu

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

fix: conflicts and strip-dashed #1998

Merged
merged 7 commits into from Sep 7, 2021
Merged

fix: conflicts and strip-dashed #1998

merged 7 commits into from Sep 7, 2021

Conversation

jly36963
Copy link
Contributor

@jly36963 jly36963 commented Aug 4, 2021

Addresses: #1952

Problem

When strip-dashed is true, the kebab case arguments are removed from argv.
When looking for conflicts, the result is a false negative. The conflicts are in kebab case while the argv arguments are in camel case, so the conflicts logic will never match the conflicting arguments.

Solution

When strip dashed is true, compare camelCase versions of conflicting against argv, to address the disparity between argv (camel) and conflicting (kebab).

Notes

This is important; please read

I didn't want to add any extra dependencies, so I made a very lightweight implementation of camelCase.
I borrowed heavily from lodash's source code. Let me know if I need to add proper credit, change the solution to avoid copying someone else's code, add unit tests, etc.

if (!s) return '';
// split camel case, then match ascii words
const words = asciiWords(s.replace(/([a-z0-9])([A-Z])/g, '$1 $2'));
return words.length > 1
Copy link
Member

Choose a reason for hiding this comment

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

I think you should have access to camelCase already through the yargs-parser dependency:

https://github.com/yargs/yargs-parser/blob/main/lib/string-utils.ts#L7

I believe I already use one or two methods off of it elsewhere.

@jly36963 jly36963 requested a review from bcoe September 7, 2021 20:32
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.

None yet

2 participants