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: port --bash-completion to C++ #25901

Closed
wants to merge 3 commits into from
Closed

Conversation

@joyeecheung
Copy link
Member

joyeecheung commented Feb 3, 2019

So that it gets handle earlier and faster during the bootstrap
process.

Drive-by fixes:

  • Remove [has_eval_string] and [ssl_openssl_cert_store] from
    the completion output

Before:

_node_complete() {
  local cur_word options
  cur_word="${COMP_WORDS[COMP_CWORD]}"
  if [[ "${cur_word}" == -* ]] ; then
    COMPREPLY=( $(compgen -W '--abort-on-uncaught-exception --experimental-report --perf-basic-prof --max-old-space-size --diagnostic-report-verbose --inspect-brk-node --inspect-port --diagnostic-report-filename --diagnostic-report-uncaught-exception --track-heap-objects --diagnostic-report-signal --tls-v1.1 --napi-modules --inspect-brk --tls-v1.0 --redirect-warnings --print --trace-deprecation --trace-event-file-pattern --check --perf-prof --preserve-symlinks --no-warnings --debug --no-deprecation --trace-warnings --expose-internals --diagnostic-report-on-signal --diagnostic-report-directory --pending-deprecation --experimental-worker --trace-sync-io --diagnostic-report-on-fatalerror --tls-cipher-list --no-force-async-hooks-checks --inspect --eval --loader --use-openssl-ca --preserve-symlinks-main --interactive --icu-data-dir --v8-options --require --use-bundled-ca --experimental-policy --version --experimental-vm-modules --prof-process --max-http-header-size [has_eval_string] --throw-deprecation --completion-bash --help --zero-fill-buffers --v8-pool-size [ssl_openssl_cert_store] --experimental-modules --http-parser --openssl-config --trace-event-categories --security-reverts --experimental-repl-await --stack-trace-limit --debug-brk --title --debug-port --prof-process --debug= -p -pe -v --inspect-brk= -i --print <arg> --inspect= --debug-brk= -e --inspect-brk-node= -c -h -r --trace-events-enabled' -- "${cur_word}") )
    return 0
  else
    COMPREPLY=( $(compgen -f "${cur_word}") )
    return 0
  fi
}
complete -F _node_complete node node_g

After:

_node_complete() {
  local cur_word options
  cur_word="${COMP_WORDS[COMP_CWORD]}"
  if [[ "${cur_word}" == -* ]] ; then
    COMPREPLY=( $(compgen -W '--abort-on-uncaught-exception --experimental-report --perf-basic-prof --max-old-space-size --diagnostic-report-verbose --inspect-brk-node --inspect-port --diagnostic-report-filename --diagnostic-report-uncaught-exception --track-heap-objects --diagnostic-report-signal --tls-v1.1 --napi-modules --inspect-brk --tls-v1.0 --redirect-warnings --print --trace-deprecation --trace-event-file-pattern --check --perf-prof --preserve-symlinks --no-warnings --debug --no-deprecation --trace-warnings --expose-internals --diagnostic-report-on-signal --diagnostic-report-directory --pending-deprecation --experimental-worker --trace-sync-io --diagnostic-report-on-fatalerror --tls-cipher-list --no-force-async-hooks-checks --inspect --eval --loader --use-openssl-ca --preserve-symlinks-main --interactive --icu-data-dir --v8-options --require --use-bundled-ca --experimental-policy --version --experimental-vm-modules --prof-process --max-http-header-size --throw-deprecation --completion-bash --help --zero-fill-buffers --v8-pool-size --experimental-modules --http-parser --openssl-config --trace-event-categories --security-reverts --experimental-repl-await --stack-trace-limit --debug-brk --title --debug-port --prof-process --debug= -p -pe -v --inspect-brk= -i --print <arg> --inspect= --debug-brk= -e --inspect-brk-node= -c -h -r --trace-events-enabled' -- "${cur_word}") )
    return 0
  else
    COMPREPLY=( $(compgen -f "${cur_word}") )
    return 0
  fi
}
complete -F _node_complete node node_g
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Copy link
Member

addaleax left a comment

I'm wondering if keeping this in JS is worth it, because that makes it more accessible to people? I realize it's slower, but we encourage people to write the output to a file anyway, so I wouldn't do this for performance reasons

@@ -400,6 +401,7 @@ class OptionsParser {
friend class OptionsParser;

friend void GetOptions(const v8::FunctionCallbackInfo<v8::Value>& args);
friend std::string GetBashCompletion();

This comment has been minimized.

Copy link
@addaleax

addaleax Feb 3, 2019

Member

This could also be a member of OptionsParser, right?

This comment has been minimized.

Copy link
@joyeecheung

joyeecheung Feb 17, 2019

Author Member

It can, but so is GetOptions() so I figured it's better to keep them consistent

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Feb 6, 2019

@addaleax IMO it is an overkill to implement --bash-completion in JS, and being in JS does not necessarily mean it's more accessible. This flag essentially just formats structured data from the binary into a string and prints it to stdout, there is no user input or error handling necessary. Implementing it in JS means it has to depend on a working v8 isolate and an Environment, and rely on proper serialization of a complicated v8::Object as well as a working stdout stream, those are all too complicated for a simple feature like --bash-completion. (In fact to remove [has_eval_string] and [ssl_openssl_cert_store] my first action was to debug GetOptions() since that's where all the complexities were, it was much easier to debug the loop in GetBashCompletion() to be honest, so moving the formatting in JS did not really make the implementation any more accessible if the source of data is in C++)

Being handled later in time (after bootstrap/node.js instead of directly in node::Init) also means that there is a mental burden when we add branches in the bootstrap (e.g. node-report) even though they do not really make sense for --bash-completion so we might as well just deal with it earlier and focus on cases that are more common in the bootstrap process - this is also the case for things like node --version.

@devsnek
devsnek approved these changes Feb 6, 2019
@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Feb 17, 2019

@addaleax: is your comment in #25901 (review) blocking?

@addaleax

This comment has been minimized.

Copy link
Member

addaleax commented Feb 17, 2019

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 5, 2019

@joyeecheung this needs a rebase

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Mar 27, 2019

@joyeecheung joyeecheung force-pushed the joyeecheung:cpp-bash branch from b23997e to 6635c6e Apr 2, 2019
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@joyeecheung joyeecheung force-pushed the joyeecheung:cpp-bash branch from 6635c6e to 2911595 May 11, 2019
So that it gets handle earlier and faster during the bootstrap
process.

Drive-by fixes:

- Remove `[has_eval_string]` and `[ssl_openssl_cert_store]` from
  the completion output
- Set `kProfProcess` execution mode for `--prof-process` instead
  of `kPrintBashProcess` which is removed in this patch.
- Append new line to the end of the output of --bash-completion
@joyeecheung joyeecheung force-pushed the joyeecheung:cpp-bash branch from 2911595 to 3190ae1 May 11, 2019
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented May 12, 2019

Fixed the Windows failure. @devsnek @jasnell @addaleax can you take a look again? Thanks!

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented May 20, 2019

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@addaleax

This comment has been minimized.

Copy link
Member

addaleax commented May 22, 2019

@joyeecheung Since you pinged me – the code changes look good to me, but I’d still have a mild preference to keep this in JS because that does seem to be less complex to me. But as far as I’m concerned, this PR is ready to land 👍 (I can’t make out what the Windows failure is, so I’ll just start a resume CI…)

@nodejs-github-bot

This comment has been minimized.

@Trott Trott force-pushed the nodejs:master branch from 1ecc406 to 49cf67e Sep 17, 2019
@fhinkel

This comment has been minimized.

Copy link
Member

fhinkel commented Oct 28, 2019

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

BridgeAR added a commit that referenced this pull request Dec 25, 2019
So that it gets handle earlier and faster during the bootstrap
process.

Drive-by fixes:

- Remove `[has_eval_string]` and `[ssl_openssl_cert_store]` from
  the completion output
- Set `kProfProcess` execution mode for `--prof-process` instead
  of `kPrintBashProcess` which is removed in this patch.
- Append new line to the end of the output of --bash-completion

PR-URL: #25901
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Dec 25, 2019

Landed in 403c84a 🎉

@BridgeAR BridgeAR closed this Dec 25, 2019
BridgeAR added a commit that referenced this pull request Jan 3, 2020
So that it gets handle earlier and faster during the bootstrap
process.

Drive-by fixes:

- Remove `[has_eval_string]` and `[ssl_openssl_cert_store]` from
  the completion output
- Set `kProfProcess` execution mode for `--prof-process` instead
  of `kPrintBashProcess` which is removed in this patch.
- Append new line to the end of the output of --bash-completion

PR-URL: #25901
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Jan 7, 2020
targos added a commit that referenced this pull request Jan 14, 2020
So that it gets handle earlier and faster during the bootstrap
process.

Drive-by fixes:

- Remove `[has_eval_string]` and `[ssl_openssl_cert_store]` from
  the completion output
- Set `kProfProcess` execution mode for `--prof-process` instead
  of `kPrintBashProcess` which is removed in this patch.
- Append new line to the end of the output of --bash-completion

PR-URL: #25901
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.