| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4f95213 commit 715c158
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,7 +139,6 @@ | |||
| 139 | 139 | 'lib/internal/main/eval_string.js', | |
| 140 | 140 | 'lib/internal/main/eval_stdin.js', | |
| 141 | 141 | 'lib/internal/main/inspect.js', | |
| 142 | - 'lib/internal/main/print_bash_completion.js', | ||
| 143 | 142 | 'lib/internal/main/print_help.js', | |
| 144 | 143 | 'lib/internal/main/prof_process.js', | |
| 145 | 144 | 'lib/internal/main/repl.js', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -400,9 +400,6 @@ MaybeLocal<Value> StartMainThreadExecution(Environment* env) { | |||
| 400 | 400 | return StartExecution(env, "internal/main/print_help"); | |
| 401 | 401 | } | |
| 402 | 402 | ||
| 403 | - if (per_process::cli_options->print_bash_completion) { | ||
| 404 | - return StartExecution(env, "internal/main/print_bash_completion"); | ||
| 405 | - } | ||
| 406 | 403 | ||
| 407 | 404 | if (env->options()->prof_process) { | |
| 408 | 405 | return StartExecution(env, "internal/main/prof_process"); | |
@@ -875,6 +872,12 @@ void Init(int* argc, | |||
| 875 | 872 | exit(0); | |
| 876 | 873 | } | |
| 877 | 874 | ||
| 875 | + if (per_process::cli_options->print_bash_completion) { | ||
| 876 | + std::string completion = options_parser::GetBashCompletion(); | ||
| 877 | + printf("%s\n", completion.c_str()); | ||
| 878 | + exit(0); | ||
| 879 | + } | ||
| 880 | + | ||
| 878 | 881 | if (per_process::cli_options->print_v8_help) { | |
| 879 | 882 | V8::SetFlagsFromString("--help", 6); // Doesn't return. | |
| 880 | 883 | UNREACHABLE(); | |
@@ -944,6 +947,12 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) { | |||
| 944 | 947 | return result; | |
| 945 | 948 | } | |
| 946 | 949 | ||
| 950 | + if (per_process::cli_options->print_bash_completion) { | ||
| 951 | + std::string completion = options_parser::GetBashCompletion(); | ||
| 952 | + printf("%s\n", completion.c_str()); | ||
| 953 | + exit(0); | ||
| 954 | + } | ||
| 955 | + | ||
| 947 | 956 | if (per_process::cli_options->print_v8_help) { | |
| 948 | 957 | V8::SetFlagsFromString("--help", 6); // Doesn't return. | |
| 949 | 958 | UNREACHABLE(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,8 @@ | |||
| 4 | 4 | #include "env-inl.h" | |
| 5 | 5 | #include "node_binding.h" | |
| 6 | 6 | ||
| 7 | + #include <errno.h> | ||
| 8 | + #include <sstream> | ||
| 7 | 9 | #include <cstdlib> // strtoul, errno | |
| 8 | 10 | ||
| 9 | 11 | using v8::Boolean; | |
@@ -847,6 +849,43 @@ HostPort SplitHostPort(const std::string& arg, | |||
| 847 | 849 | ParseAndValidatePort(arg.substr(colon + 1), errors) }; | |
| 848 | 850 | } | |
| 849 | 851 | ||
| 852 | + std::string GetBashCompletion() { | ||
| 853 | + Mutex::ScopedLock lock(per_process::cli_options_mutex); | ||
| 854 | + const auto& parser = _ppop_instance; | ||
| 855 | + | ||
| 856 | + std::ostringstream out; | ||
| 857 | + | ||
| 858 | + out << "_node_complete() {\n" | ||
| 859 | + " local cur_word options\n" | ||
| 860 | + " cur_word=\"${COMP_WORDS[COMP_CWORD]}\"\n" | ||
| 861 | + " if [[ \"${cur_word}\" == -* ]] ; then\n" | ||
| 862 | + " COMPREPLY=( $(compgen -W '"; | ||
| 863 | + | ||
| 864 | + for (const auto& item : parser.options_) { | ||
| 865 | + if (item.first[0] != '[') { | ||
| 866 | + out << item.first << " "; | ||
| 867 | + } | ||
| 868 | + } | ||
| 869 | + for (const auto& item : parser.aliases_) { | ||
| 870 | + if (item.first[0] != '[') { | ||
| 871 | + out << item.first << " "; | ||
| 872 | + } | ||
| 873 | + } | ||
| 874 | + if (parser.aliases_.size() > 0) { | ||
| 875 | + out.seekp(-1, out.cur); // Strip the trailing space | ||
| 876 | + } | ||
| 877 | + | ||
| 878 | + out << "' -- \"${cur_word}\") )\n" | ||
| 879 | + " return 0\n" | ||
| 880 | + " else\n" | ||
| 881 | + " COMPREPLY=( $(compgen -f \"${cur_word}\") )\n" | ||
| 882 | + " return 0\n" | ||
| 883 | + " fi\n" | ||
| 884 | + "}\n" | ||
| 885 | + "complete -F _node_complete node node_g"; | ||
| 886 | + return out.str(); | ||
| 887 | + } | ||
| 888 | + | ||
| 850 | 889 | // Return a map containing all the options and their metadata as well | |
| 851 | 890 | // as the aliases | |
| 852 | 891 | void GetOptions(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -255,6 +255,7 @@ namespace options_parser { | |||
| 255 | 255 | HostPort SplitHostPort(const std::string& arg, | |
| 256 | 256 | std::vector<std::string>* errors); | |
| 257 | 257 | void GetOptions(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 258 | + std::string GetBashCompletion(); | ||
| 258 | 259 | ||
| 259 | 260 | enum OptionType { | |
| 260 | 261 | kNoOp, | |
@@ -438,6 +439,7 @@ class OptionsParser { | |||
| 438 | 439 | friend class OptionsParser; | |
| 439 | 440 | ||
| 440 | 441 | friend void GetOptions(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 442 | + friend std::string GetBashCompletion(); | ||
| 441 | 443 | }; | |
| 442 | 444 | ||
| 443 | 445 | using StringVector = std::vector<std::string>; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,22 +2,32 @@ | |||
| 2 | 2 | require('../common'); | |
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const child_process = require('child_process'); | |
| 5 | + const { inspect } = require('util'); | ||
| 5 | 6 | ||
| 6 | 7 | const p = child_process.spawnSync( | |
| 7 | 8 | process.execPath, [ '--completion-bash' ]); | |
| 8 | 9 | assert.ifError(p.error); | |
| 9 | - assert.ok(p.stdout.toString().includes( | ||
| 10 | - `_node_complete() { | ||
| 10 | + | ||
| 11 | + const output = p.stdout.toString().trim().replace(/\r/g, ''); | ||
| 12 | + console.log(output); | ||
| 13 | + | ||
| 14 | + const prefix = `_node_complete() { | ||
| 11 | 15 | local cur_word options | |
| 12 | 16 | cur_word="\${COMP_WORDS[COMP_CWORD]}" | |
| 13 | 17 | if [[ "\${cur_word}" == -* ]] ; then | |
| 14 | - COMPREPLY=( $(compgen -W '`)); | ||
| 15 | - assert.ok(p.stdout.toString().includes( | ||
| 16 | - `' -- "\${cur_word}") ) | ||
| 18 | + COMPREPLY=( $(compgen -W '`.replace(/\r/g, ''); | ||
| 19 | + const suffix = `' -- "\${cur_word}") ) | ||
| 17 | 20 | return 0 | |
| 18 | 21 | else | |
| 19 | 22 | COMPREPLY=( $(compgen -f "\${cur_word}") ) | |
| 20 | 23 | return 0 | |
| 21 | 24 | fi | |
| 22 | 25 | } | |
| 23 | - complete -F _node_complete node node_g`)); | ||
| 26 | + complete -F _node_complete node node_g`.replace(/\r/g, ''); | ||
| 27 | + | ||
| 28 | + assert.ok( | ||
| 29 | + output.includes(prefix), | ||
| 30 | + `Expect\n\n ${inspect(output)}\n\nto include\n\n${inspect(prefix)}`); | ||
| 31 | + assert.ok( | ||
| 32 | + output.includes(suffix), | ||
| 33 | + `Expect\n\n ${inspect(output)}\n\nto include\n\n${inspect(suffix)}`); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments