-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
There was a problem hiding this 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), |
There was a problem hiding this comment.
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!') |
There was a problem hiding this comment.
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!?!') |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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(/^-+/, '') |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I've captured the comments in this PR as issues and will land the PR as is. |
Initial work here for review and consideration.
Please review: @bcoe @darcyclarke @ruyadorno @iansu
Thanks!