summaryrefslogtreecommitdiff
path: root/src/node_options.cc
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2018-09-19 07:33:28 +0200
committerAnna Henningsen <anna@addaleax.net>2018-09-22 12:00:28 +0200
commit36bdd19a6b3aee18143a3d45d6eedc19a2e95189 (patch)
treea113044ac7f192fda85ea0a24708fb8e1333a6f4 /src/node_options.cc
parent1f4d4c0da87db42f97f43d8374967071fe85b37a (diff)
downloadnode-new-36bdd19a6b3aee18143a3d45d6eedc19a2e95189.tar.gz
src: add CheckOptions to Options classes
This commit adds a CheckOptions function that the options classes can optionally implement to check that options specified are correct (dependencies between options are met or options that are mutually exclusive). In the process of doing this the error pointer passed to Parse was changed to be of type vector so that potentially multiple options check failures can be reported. PR-URL: https://github.com/nodejs/node/pull/22943 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_options.cc')
-rw-r--r--src/node_options.cc38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/node_options.cc b/src/node_options.cc
index 1a614d0e77..156ea11fe9 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -16,6 +16,32 @@ using v8::Undefined;
using v8::Value;
namespace node {
+
+void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
+#if HAVE_OPENSSL
+ if (use_openssl_ca && use_bundled_ca) {
+ errors->push_back("either --use-openssl-ca or --use-bundled-ca can be "
+ "used, not both");
+ }
+#endif
+ per_isolate->CheckOptions(errors);
+}
+
+void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {
+ per_env->CheckOptions(errors);
+}
+
+void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
+ if (!userland_loader.empty() && !experimental_modules) {
+ errors->push_back("--loader requires --experimental-modules be enabled");
+ }
+
+ if (syntax_check_only && has_eval_string) {
+ errors->push_back("either --check or --eval can be used, not both");
+ }
+ debug_options->CheckOptions(errors);
+}
+
namespace options_parser {
// XXX: If you add an option here, please also add it to doc/node.1 and
@@ -305,18 +331,20 @@ inline std::string RemoveBrackets(const std::string& host) {
return host;
}
-inline int ParseAndValidatePort(const std::string& port, std::string* error) {
+inline int ParseAndValidatePort(const std::string& port,
+ std::vector<std::string>* errors) {
char* endptr;
errno = 0;
const long result = strtol(port.c_str(), &endptr, 10); // NOLINT(runtime/int)
if (errno != 0 || *endptr != '\0'||
(result != 0 && result < 1024) || result > 65535) {
- *error = "Port must be 0 or in range 1024 to 65535.";
+ errors->push_back(" must be 0 or in range 1024 to 65535.");
}
return static_cast<int>(result);
}
-HostPort SplitHostPort(const std::string& arg, std::string* error) {
+HostPort SplitHostPort(const std::string& arg,
+ std::vector<std::string>* errors) {
// remove_brackets only works if no port is specified
// so if it has an effect only an IPv6 address was specified.
std::string host = RemoveBrackets(arg);
@@ -332,11 +360,11 @@ HostPort SplitHostPort(const std::string& arg, std::string* error) {
return HostPort { arg, -1 };
}
}
- return HostPort { "", ParseAndValidatePort(arg, error) };
+ return HostPort { "", ParseAndValidatePort(arg, errors) };
}
// Host and port found:
return HostPort { RemoveBrackets(arg.substr(0, colon)),
- ParseAndValidatePort(arg.substr(colon + 1), error) };
+ ParseAndValidatePort(arg.substr(colon + 1), errors) };
}
// Usage: Either: