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

src: add getopt option parser #1804

Merged
merged 1 commit into from
Jun 1, 2015
Merged

src: add getopt option parser #1804

merged 1 commit into from
Jun 1, 2015

Conversation

evanlucas
Copy link
Contributor

Initial getopt implementation for option parsing. Supersedes #1726.

I split out the actual options to try and make it more maintainable.

@mscdex
Copy link
Contributor

mscdex commented May 27, 2015

It would be nice if we could generate the help text from the defined options. That would help avoid duplication.

@evanlucas
Copy link
Contributor Author

I think that's definitely doable. I'll see if I can add that tonight.

@evanlucas evanlucas force-pushed the getopt branch 5 times, most recently from dd59140 to b06ff7b Compare May 27, 2015 05:27
@evanlucas
Copy link
Contributor Author

Ok, help is automatically generated now too :]

* string begins with a '+'.
*/
if (posixly_correct == -1 || optreset)
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
Copy link
Member

Choose a reason for hiding this comment

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

I suggest you remove this code. I don't think many people would expect POSIXLY_CORRECT to affect the iojs binary.

@evanlucas evanlucas force-pushed the getopt branch 2 times, most recently from c78d8f8 to 65a192e Compare May 27, 2015 18:11
@brendanashworth brendanashworth added the c++ Issues and PRs that require attention from people who are familiar with C++. label May 27, 2015
@evanlucas
Copy link
Contributor Author

Switched to use a global variable node_options

@@ -178,6 +179,7 @@ typedef intptr_t ssize_t;

namespace node {

NODE_EXTERN extern NodeOptions node_options;
Copy link
Member

Choose a reason for hiding this comment

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

For the love of $DEITY, please don't make this public.

@bnoordhuis
Copy link
Member

It's probably a good idea to add some option parsing regression tests.

@evanlucas
Copy link
Contributor Author

Ok, made requested changes and added tests for options that are not currently being tested

// test --help
var child = spawn(process.execPath, ['--help']);
child.stdout.on('data', function(chunk) {
assert.equal(/Usage/.test(chunk.toString()), true);
Copy link
Member

Choose a reason for hiding this comment

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

This is not 100% sound, the output can get split over multiple chunks. Can I suggest you use spawnSync instead?

EDIT: Or execFile, like you do below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will update that now. Want me to do that on all of these tests?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please.

@bnoordhuis
Copy link
Member

LGTM with nits and assuming the CI is happy.

@evanlucas
Copy link
Contributor Author

@evanlucas evanlucas force-pushed the getopt branch 3 times, most recently from a7752f6 to 68357e3 Compare May 29, 2015 16:39
@evanlucas
Copy link
Contributor Author

Ok, working on SmartOS support right now. Will run another CI once I get that done.

@evanlucas evanlucas force-pushed the getopt branch 2 times, most recently from 3019a34 to eadc181 Compare May 29, 2015 18:41
@evanlucas
Copy link
Contributor Author

Ok, final CI: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/736/

Last one had failures related to #1837.

@evanlucas
Copy link
Contributor Author

Does this need to wait until 3.0?

@bnoordhuis
Copy link
Member

If there are no user-visible changes, it can go into a patch release.

@evanlucas
Copy link
Contributor Author

The actual help message that is printed is slightly different since it is automatically generated based on the options.

Options have been moved into the NodeOptions class.
A new global, node_options now exists and is used
to access the options after the command line arguments
have been parsed.

PR-URL: nodejs#1804
Reviewed-By: Ben Noordhuis <[email protected]>
@evanlucas evanlucas closed this Jun 1, 2015
@evanlucas evanlucas deleted the getopt branch June 1, 2015 13:42
@evanlucas evanlucas merged commit c0e7bf2 into nodejs:master Jun 1, 2015
@evanlucas
Copy link
Contributor Author

Landed in c0e7bf2. Thanks for the multiple reviews @bnoordhuis

@jbergstroem
Copy link
Member

When this lands again, could we possibly look at expanding the cctest suite?

@evanlucas
Copy link
Contributor Author

sure

andrewdeandrade pushed a commit to andrewdeandrade/node that referenced this pull request Jun 3, 2015
Options have been moved into the NodeOptions class.
A new global, node_options now exists and is used
to access the options after the command line arguments
have been parsed.

PR-URL: nodejs/node#1804
Reviewed-By: Ben Noordhuis <[email protected]>
@rvagg rvagg mentioned this pull request Jun 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants