Permalink
Browse files

src: add kUInteger parsing

This commit adds support for uint64_t option parsing.

PR-URL: #24811
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information...
mcollina authored and MylesBorins committed Dec 18, 2018
1 parent 0057af2 commit c80ac7fae317e915d08ea0635faede30d1ab98db
Showing with 26 additions and 0 deletions.
  1. +1 −0 lib/internal/print_help.js
  2. +16 −0 src/node_options-inl.h
  3. +4 −0 src/node_options.cc
  4. +5 −0 src/node_options.h
@@ -69,6 +69,7 @@ function getArgDescription(type) {
case 'kHostPort':
return '[host:]port';
case 'kInteger':
case 'kUInteger':
case 'kString':
case 'kStringList':
return '...';
@@ -39,6 +39,19 @@ void OptionsParser<Options>::AddOption(const std::string& name,
help_text});
}

template <typename Options>
void OptionsParser<Options>::AddOption(const std::string& name,
const std::string& help_text,
uint64_t Options::* field,
OptionEnvvarSettings env_setting) {
options_.emplace(
name,
OptionInfo{kUInteger,
std::make_shared<SimpleOptionField<uint64_t>>(field),
env_setting,
help_text});
}

template <typename Options>
void OptionsParser<Options>::AddOption(const std::string& name,
const std::string& help_text,
@@ -401,6 +414,9 @@ void OptionsParser<Options>::Parse(
case kInteger:
*Lookup<int64_t>(info.field, options) = std::atoll(value.c_str());
break;
case kUInteger:
*Lookup<uint64_t>(info.field, options) = std::stoull(value.c_str());
break;
case kString:
*Lookup<std::string>(info.field, options) = value;
break;
@@ -422,6 +422,9 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
case kInteger:
value = Number::New(isolate, *parser.Lookup<int64_t>(field, opts));
break;
case kUInteger:
value = Number::New(isolate, *parser.Lookup<uint64_t>(field, opts));
break;
case kString:
if (!ToV8Value(context, *parser.Lookup<std::string>(field, opts))
.ToLocal(&value)) {
@@ -509,6 +512,7 @@ void Initialize(Local<Object> target,
NODE_DEFINE_CONSTANT(types, kV8Option);
NODE_DEFINE_CONSTANT(types, kBoolean);
NODE_DEFINE_CONSTANT(types, kInteger);
NODE_DEFINE_CONSTANT(types, kUInteger);
NODE_DEFINE_CONSTANT(types, kString);
NODE_DEFINE_CONSTANT(types, kHostPort);
NODE_DEFINE_CONSTANT(types, kStringList);
@@ -203,6 +203,7 @@ enum OptionType {
kV8Option,
kBoolean,
kInteger,
kUInteger,
kString,
kHostPort,
kStringList,
@@ -229,6 +230,10 @@ class OptionsParser {
const std::string& help_text,
bool Options::* field,
OptionEnvvarSettings env_setting = kDisallowedInEnvironment);
void AddOption(const std::string& name,
const std::string& help_text,
uint64_t Options::* field,
OptionEnvvarSettings env_setting = kDisallowedInEnvironment);
void AddOption(const std::string& name,
const std::string& help_text,
int64_t Options::* field,

0 comments on commit c80ac7f

Please sign in to comment.