Skip to content

Commit

Permalink
src: add kUInteger parsing
Browse files Browse the repository at this point in the history
This commit adds support for uint64_t option parsing.

Backport-PR-URL: #25168
PR-URL: #24811
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
mcollina authored and MylesBorins committed Dec 25, 2018
1 parent 6183c71 commit a57aed1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/internal/print_help.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function getArgDescription(type) {
case 'kHostPort':
return '[host:]port';
case 'kInteger':
case 'kUInteger':
case 'kString':
case 'kStringList':
return '...';
Expand Down
16 changes: 16 additions & 0 deletions src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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,
Expand Down Expand Up @@ -397,6 +410,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;
Expand Down
4 changes: 4 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,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)) {
Expand Down Expand Up @@ -492,6 +495,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);
Expand Down
5 changes: 5 additions & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ enum OptionType {
kV8Option,
kBoolean,
kInteger,
kUInteger,
kString,
kHostPort,
kStringList,
Expand All @@ -194,6 +195,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,
Expand Down

0 comments on commit a57aed1

Please sign in to comment.