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

Initial work on parseArgs #1

Merged
merged 3 commits into from
Apr 30, 2021
Merged

Initial work on parseArgs #1

merged 3 commits into from
Apr 30, 2021

Conversation

joesepi
Copy link
Collaborator

@joesepi joesepi commented Apr 7, 2021

Initial work here for review and consideration.

Please review: @bcoe @darcyclarke @ruyadorno @iansu

Thanks!

test/index.js Show resolved Hide resolved
Copy link
Collaborator

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

This looks like a great simple start. With regards to single dash options -rf, sounds like they just aren't yet implemented?

'use strict';

const parseArgs = (
argv = process.argv.slice(require.main ? 2 : 1),
Copy link
Collaborator

Choose a reason for hiding this comment

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

we might want to extend this further to handle environments like electron, I'm not sure of the best approach. Here's what we do in yargs.

options = {}
) => {
if (typeof options !== 'object' || options === null) {
throw new Error('Whoops!')
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps open a tracking ticket to add a clearer type checking message eventually 😆 (if you'd like to land this with Whoops!).

}
// look for shortcodes: -fXzy
else if (arg.charAt(1) !== '-') {
throw new Error('What are we doing with shortcodes!?!')
Copy link
Collaborator

Choose a reason for hiding this comment

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

for this first implementation we're only supporting --foo, --foo bar?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I read the FAQ, and opened #2.


// Any number of leading dashes are allowed
// remove all leading dashes
arg = arg.replace(/^-+/, '')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I could do -----hello world? I guess, why not?

@@ -4,7 +4,7 @@
"description": "Polyfill of future proposal for `util.parseArgs()`",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test/index.js"
Copy link
Collaborator

Choose a reason for hiding this comment

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

For test coverage, which I think will be helpful for writing a parser, I suggest we try c8 which is what I've got the Node.js using 😄

Also, I think it would be nice to pull in standard or standardx as a linter, I usually do this:

"posttest": "standard",
"fix": "standard --fix"

That way someone can just run npm run fix, to address linting issues.

Copy link
Member

Choose a reason for hiding this comment

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

let's please just use eslint, regardless of how it's configured; that package's name doesn't need any additional artificial inflation of its standard-ness.

@joesepi
Copy link
Collaborator Author

joesepi commented Apr 30, 2021

I've captured the comments in this PR as issues and will land the PR as 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.

6 participants