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

doc, src: sort cli cmd options and env vars #19878

Closed

Conversation

willhayslett
Copy link
Contributor

Alphabetizing the command line options and environment
variables in doc/api/cli.md for consistency and readability.

Refs: #19814

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added cli Issues and PRs related to the Node.js command line interface. doc Issues and PRs related to the documentations. labels Apr 8, 2018
@vsemozhetbyt
Copy link
Contributor

Tricky diff)

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 8, 2018

Let's do the check in some steps.

  1. Sort all lines in temporal copies of both versions, compare the result and make sure nothing unwanted is added/deleted.

Found now during the comparison:

  • + 14 blank lines: more consistent space between sections, this is good.
  • These changes in metadata seem accidental?
### `--force-fips`
<!-- YAML
- added: v6.0.0
 -->

### `--force-fips`
<!-- YAML
+added:
+  - v5.0.0
+  - v4.2.0
+changes:
+  - version: REPLACEME
+    pr-url: https://github.com/nodejs/node/pull/19600
+    description: The `--require` option is now supported when checking a file.
 -->
### `-c`, `--check`
<!-- YAML
added:
  - v5.0.0
  - v4.2.0
-changes:
-  - version: REPLACEME
-    pr-url: https://github.com/nodejs/node/pull/19600
-    description: The `--require` option is now supported when checking a file.
 -->

### `-c`, `--check`
<!-- YAML
added:
  - v5.0.0
  - v4.2.0
 -->

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 8, 2018

While fixing the metadata change, you can also add an extra blank line between ### `NODE_NO_WARNINGS=1` and ### `NODE_OPTIONS=options...` sections for consistensy.

@willhayslett
Copy link
Contributor Author

willhayslett commented Apr 8, 2018

Yes, very tricky diff; thank you for the thorough review!

I got a little tripped up on the force-fips metadata changes. Encountered a conflict with the following sha while rebasing:

0876a03#diff-85b6573bc4afd5e06ed3b9d9b553635d

Looks like the force-fips change is correct, but the removal from --check isn't.

EDIT: Looks like the metadata between those options got switched.

I'll go ahead get this updated along with the blank lines, but let me know if that doesn't seem correct.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 8, 2018

It seems the removal from --check isn't correct, but I doubt if --force-fips change is correct: the changed and added metadata seems just copied from the --check change. Maybe --force-fips change should be reverted and --check metadata updated (during rebase or in a manual way)?

@willhayslett
Copy link
Contributor Author

@vsemozhetbyt, you're right. Making these changes now.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 8, 2018

  • Sort all lines in temporal copies of both versions, compare the result and make sure nothing unwanted is added/deleted. — Check!

Now I am trying to find a way to check if nothing is changed inside the reordered sections by chance...

@willhayslett
Copy link
Contributor Author

@vsemozhetbyt it's definitely non-trivial to sift through the changes.

I'm also working on making the same adjustments in node.cc so the options/vars are sorted when executing node --help.

If there happens to be a better way to do it so the diff isn't so difficult to read, please let me know.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 8, 2018

I am not aware of any simpler way(

But to check if the sections are not changed I've used this trick

  1. Replace in both versions /\n(?!#|\[.+\]:)/ with ' ' to make all the sections one-liners (except bottom references).
  2. Trim trailing spaces.
  3. Sort all lines.
  4. The files should be equals.

And they are!

@vsemozhetbyt
Copy link
Contributor

Sorting is also OK.

Copy link
Contributor

@vsemozhetbyt vsemozhetbyt left a comment

Choose a reason for hiding this comment

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

For now:

  • Nothing is added or deleted except appropriate new lines.
  • Nothing is regrouped inside the sections.
  • Sorting is right.

@vsemozhetbyt
Copy link
Contributor

@vsemozhetbyt
Copy link
Contributor

Changes in node.cc can be added to this PR as a separate commit.

@willhayslett
Copy link
Contributor Author

@vsemozhetbyt, as there were some logic changes with the latest commit, I'd like to take a stab at creating some c++ tests before this moves forward.

Also, noticed some cli options enumerated in node.cc that are not in doc/api/cli.md. Specifically the following:

--napi-modules
--v8-pool-size=num
--experimental-modules
--experimental-vm-modules

Should I add those to the doc as part of this PR or create a different one?

@vsemozhetbyt
Copy link
Contributor

I think as we are at this so deep and as we've already added some things from cli.md to node.cc, we can also do vice-versa. Just let's do it in a separate commit so that the first one remains reordering only, to not overcomplicate it.

@willhayslett
Copy link
Contributor Author

Got it, @vsemozhetbyt!

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 8, 2018

So, I do not know C++, so the second commit needs to be reviewed by someone else. Maybe @Trott?
I just can find out this diffs resume with "sort-all-lines-and-compare" hack described above:

+         "  --                         indicate the end of node options\n"

+         "  -h, --help                 print node command line options\n"

+#if defined(NODE_HAVE_I18N_SUPPORT)
+         "NODE_PRESERVE_SYMLINKS       set to 1 to preserve symbolic links\n"
+         "                             when resolving and caching modules\n"
+#endif

(TBH, I do not know why NODE_HAVE_I18N_SUPPORT affects NODE_PRESERVE_SYMLINKS. Is this true?)

-         "  -                          script read from stdin (default; "
-         "interactive mode if a tty)\n"
+         "  -                          script read from stdin (default; \n"
+         "                             interactive mode if a tty)\n"

-    "--require", "-r",
+    "--require",
...
+    "-r",

And also these added and deleted lines in various places:

-#endif  /* NODE_FIPS_MODE */
-#endif /* HAVE_OPENSSL */
+#endif  // defined(NODE_HAVE_I18N_SUPPORT)
+#endif  // defined(NODE_HAVE_I18N_SUPPORT)
+#endif  // HAVE_INSPECTOR
+#endif  // HAVE_OPENSSL
+#endif  // HAVE_OPENSSL
+#endif  // HAVE_OPENSSL
+#endif  // HAVE_OPENSSL
+#endif  // NODE_FIPS_MODE
+#if defined(NODE_HAVE_I18N_SUPPORT)
+#if defined(NODE_HAVE_I18N_SUPPORT)
+#if HAVE_OPENSSL
+#if HAVE_OPENSSL
+#if HAVE_OPENSSL

@vsemozhetbyt
Copy link
Contributor

Intermediate full CI to check the current stage: https://ci.nodejs.org/job/node-test-pull-request/14131/

@vsemozhetbyt
Copy link
Contributor

One fail of parallel/test-http2-stream-client may be unrelated.

@Trott
Copy link
Member

Trott commented Apr 9, 2018

One fail of parallel/test-http2-stream-client may be unrelated.

Indeed, appears unrelated. Should re-run node-test-commit-linux just to set a good example if nothing else. (Well, that and I think our current governance rules require it.) But I can't restart or add any node-test-commit-linux jobs right now. They just disappear in CI. @nodejs/build

@rvagg
Copy link
Member

rvagg commented Apr 9, 2018

I found a job (git-clean-rpi) that had a big queue cause old machines it was trying to run had been removed. I've fixed that up for now and new runs seem to be going through. I'm going to restart jenkins when I see it idle but for now it seems to be working OK.

@willhayslett
Copy link
Contributor Author

(TBH, I do not know why NODE_HAVE_I18N_SUPPORT affects NODE_PRESERVE_SYMLINKS. Is this true?)

I'm curious about this as well. I added that check because the --preserve-symlinks option likewise appears to be wrapped in a preprocessor check for NODE_HAVE_I18N_SUPPORT:

-#if defined(NODE_HAVE_I18N_SUPPORT)
-         "  --icu-data-dir=dir         set ICU data load path to dir\n"
-         "                             (overrides NODE_ICU_DATA)\n"
-#if !defined(NODE_HAVE_SMALL_ICU)
-         "                             note: linked-in ICU data is present\n"
-#endif
-         "  --preserve-symlinks        preserve symbolic links when resolving\n"
-         "  --experimental-modules     experimental ES Module support\n"
-         "                             and caching modules\n"
-         "  --experimental-vm-modules  experimental ES Module support\n"
-         "                             in vm module\n"
-#endif

I may be reading the code wrong (which very well may be the case as I don't know c++ either), but if NODE_HAVE_I18N_SUPPORT doesn't impact --preserve-symlinks (or --experimental-modules and --experimental-vm-modules), there may be a pre-existing bug.

@rvagg
Copy link
Member

rvagg commented Apr 9, 2018

node-test-pull-request @ https://ci.nodejs.org/job/node-test-pull-request/14133/

I think you need to also edit doc/node.1 for completeness here, it has the same list of arguments in the same order I think. So you'd better get your roff on and figure that one out too (man -l doc/node.1 to test it btw)

@willhayslett
Copy link
Contributor Author

haha yep @rvagg! Was going to ask if that needed to be done as well. Started looking at mdoc and roff... should be fun! Thanks for the test command!

@willhayslett
Copy link
Contributor Author

Do we have a way to perform tests against different versions of the compiled binary? I'd like to validate the latest commit against different build configurations. Specifically, the output of the PrintHelp() function changes based on the following build flags:

HAVE_OPENSSL: --without-ssl
NODE_FIPS_MODE: --openssl-fips
NODE_HAVE_I18N_SUPPORT: --with-icu-path
NODE_HAVE_SMALL_ICU: --with-intl; --without-intl
HAVE_INSPECTOR: --without-inspector
NODE_OPENSSL_CERT_STORE: --openssl-use-def-ca-store
NODE_WITHOUT_NODE_OPTIONS: --without-node-options

Is there any way to test against these with the current toolset?

@vsemozhetbyt
Copy link
Contributor

function testForSubstring(options) {
if (options.compileConstant) {
options.flags.forEach((flag) => {
assert.strictEqual(true, stdOut.indexOf(flag) !== -1);
Copy link
Member

Choose a reason for hiding this comment

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

Can you swap the arguments around? assert arguments are actual, expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

});
} else {
options.flags.forEach((flag) => {
assert.strictEqual(-1, stdOut.indexOf(flag));
Copy link
Member

Choose a reason for hiding this comment

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

Can you swap the arguments around? assert arguments are actual, expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

function startPrintHelpTest() {
exec('./node --help', common.mustCall((err, stdout, stderr) => {
if (err) {
assert.ifError(err);
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be wrapped in if (err) {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done



function startPrintHelpTest() {
exec('./node --help', common.mustCall((err, stdout, stderr) => {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use process.execPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@richardlau
Copy link
Member

Test failing on Windows, e.g., https://ci.nodejs.org/job/node-test-binary-windows/16492/COMPILED_BY=vs2017,RUNNER=win10,RUN_SUBSET=1/console:

not ok 64 parallel/test-cli-node-print-help
  ---
  duration_ms: 0.140
  severity: fail
  exitcode: 1
  stack: |-
    assert.js:589
        throw newErr;
        ^
    
    AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Command failed: ./node --help
    '.' is not recognized as an internal or external command,
    operable program or batch file.
    
        at ChildProcess.exithandler (child_process.js:282:12)
        at ChildProcess.emit (events.js:182:13)
        at maybeClose (internal/child_process.js:944:16)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:233:5)
  ...

@Trott
Copy link
Member

Trott commented Apr 13, 2018

Test failing on Windows

@willhayslett Using process.execPath (as @richardlau suggests in a different comment) would seem to fix that.

Trott
Trott previously requested changes Apr 13, 2018
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

I'm putting the "Request Changes" red X here until the test is fixed. I don't want anyone to accidentally land this.

Alphabetizing the command line options and environment
variables in doc/api/cli.md for consistency and readability.

Refs: nodejs#19814
Updated the node.PrintHelp() function to return command line options
and environment variables sorted in ascii order. Additionally,
added missing options as sourced from doc/api/cli.md. Options
added include "--", "--help" and the "NODE_PRESERVE_SYMLINKS"
environment variable.

Also updated the comments in the PrintHelp() method to C++ style.

Fixes: nodejs#19814
Updated doc/api/cli.md to include command line options
being printed in the node.PrintHelp() function in src/node.cc
but weren't otherwise documented in the cli spec. Options added
include::

--napi-modules
--v8-pool-size=num
--experimental-modules
--experimental-vm-modules
Ascii sorted the node man page command line options.
This change brings sort order consistency between the
cli options displayed in doc/node.1 and the cli options
enumerated in other areas of the project.

Also rearranged the language for "--use-bundled-ca, --use-openssl-ca"
to correspond with the order of the options as displayed.

Fixes: nodejs#19814
Created tests to validate that the newly ascii sorted
cli options in the node.PrintHelp() function are being
returned according to build configurations as expected.
@willhayslett
Copy link
Contributor Author

Thanks @richardlau and @Trott, changes committed.

@vsemozhetbyt
Copy link
Contributor

CI: https://ci.nodejs.org/job/node-test-pull-request/14256/

@vsemozhetbyt
Copy link
Contributor

Is one fail of parallel/test-http-server-keep-alive-timeout in one FreeBSD machine unrelated? Are we good to land?

@refack refack added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Apr 13, 2018
@Trott
Copy link
Member

Trott commented Apr 13, 2018

@vsemozhetbyt Sure seems like it ought to be unrelated, but no landing without a green CI everywhere, so here's a FreeBSD re-run: https://ci.nodejs.org/job/node-test-commit-freebsd/16998/

@Trott Trott dismissed their stale review April 13, 2018 18:29

test fixed

@Trott
Copy link
Member

Trott commented Apr 13, 2018

This time a different test failed on FreeBSD, also seemingly unrelated.

Trying again: https://ci.nodejs.org/job/node-test-commit-freebsd/16999/

@vsemozhetbyt
Copy link
Contributor

Rerun CI is green. I will land soon if nobody objects.

@Trott
Copy link
Member

Trott commented Apr 13, 2018

Last one was green. 👍

vsemozhetbyt pushed a commit that referenced this pull request Apr 13, 2018
* Alphabetize the command line options and environment
  variables in doc/api/cli.md for consistency and readability.

* Update doc/api/cli.md to include command line options
  being printed in the `node.PrintHelp()` function in src/node.cc
  but weren't otherwise documented in the cli spec. Options added
  include:

  --napi-modules
  --v8-pool-size=num
  --experimental-modules
  --experimental-vm-modules

* ASCII sort the node man page command line options.
  This change brings sort order consistency between the
  cli options displayed in doc/node.1 and the cli options
  enumerated in other areas of the project.

  Also rearrange the language for `--use-bundled-ca`, `--use-openssl-ca`
  to correspond with the order of the options as displayed.

* Update `node.PrintHelp()` function to return command line options
  and environment variables sorted in ASCII order. Additionally,
  add missing options as sourced from doc/api/cli.md. Options
  added include `--`, `--help` and the `NODE_PRESERVE_SYMLINKS`
  environment variable.

  Also update the comments in the `node.PrintHelp()` method
  to C++ style.

* Create tests to validate that the newly ASCII sorted
  cli options in the `node.PrintHelp()` function are being
  returned according to build configurations as expected.

PR-URL: #19878
Refs: #19814
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@vsemozhetbyt
Copy link
Contributor

Squashed and landed in a43e889

@willhayslett Thank you for all the heavy lifting!
Thanks to all reviewers for the time and toil.

@willhayslett
Copy link
Contributor Author

Woo hoo! Thanks, everyone!

jasnell pushed a commit that referenced this pull request Apr 16, 2018
* Alphabetize the command line options and environment
  variables in doc/api/cli.md for consistency and readability.

* Update doc/api/cli.md to include command line options
  being printed in the `node.PrintHelp()` function in src/node.cc
  but weren't otherwise documented in the cli spec. Options added
  include:

  --napi-modules
  --v8-pool-size=num
  --experimental-modules
  --experimental-vm-modules

* ASCII sort the node man page command line options.
  This change brings sort order consistency between the
  cli options displayed in doc/node.1 and the cli options
  enumerated in other areas of the project.

  Also rearrange the language for `--use-bundled-ca`, `--use-openssl-ca`
  to correspond with the order of the options as displayed.

* Update `node.PrintHelp()` function to return command line options
  and environment variables sorted in ASCII order. Additionally,
  add missing options as sourced from doc/api/cli.md. Options
  added include `--`, `--help` and the `NODE_PRESERVE_SYMLINKS`
  environment variable.

  Also update the comments in the `node.PrintHelp()` method
  to C++ style.

* Create tests to validate that the newly ASCII sorted
  cli options in the `node.PrintHelp()` function are being
  returned according to build configurations as expected.

PR-URL: #19878
Refs: #19814
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@richardlau richardlau mentioned this pull request Apr 25, 2018
3 tasks
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 1, 2018
* Alphabetize the command line options and environment
  variables in doc/api/cli.md for consistency and readability.

* Update doc/api/cli.md to include command line options
  being printed in the `node.PrintHelp()` function in src/node.cc
  but weren't otherwise documented in the cli spec. Options added
  include:

  --napi-modules
  --v8-pool-size=num
  --experimental-modules
  --experimental-vm-modules

* ASCII sort the node man page command line options.
  This change brings sort order consistency between the
  cli options displayed in doc/node.1 and the cli options
  enumerated in other areas of the project.

  Also rearrange the language for `--use-bundled-ca`, `--use-openssl-ca`
  to correspond with the order of the options as displayed.

* Update `node.PrintHelp()` function to return command line options
  and environment variables sorted in ASCII order. Additionally,
  add missing options as sourced from doc/api/cli.md. Options
  added include `--`, `--help` and the `NODE_PRESERVE_SYMLINKS`
  environment variable.

  Also update the comments in the `node.PrintHelp()` method
  to C++ style.

* Create tests to validate that the newly ASCII sorted
  cli options in the `node.PrintHelp()` function are being
  returned according to build configurations as expected.

PR-URL: nodejs#19878
Refs: nodejs#19814
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@vsemozhetbyt vsemozhetbyt mentioned this pull request Aug 11, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues and PRs related to the Node.js command line interface. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants