Skip to content

Commit da3622e

Browse files
mcollinaMylesBorins
authored andcommitted
src: add kUInteger parsing
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]>
1 parent 809c0fe commit da3622e

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

lib/internal/print_help.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function getArgDescription(type) {
5858
case 'kHostPort':
5959
return '[host:]port';
6060
case 'kInteger':
61+
case 'kUInteger':
6162
case 'kString':
6263
case 'kStringList':
6364
return '...';

src/node_options-inl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ void OptionsParser<Options>::AddOption(const std::string& name,
3535
help_text});
3636
}
3737

38+
template <typename Options>
39+
void OptionsParser<Options>::AddOption(const std::string& name,
40+
const std::string& help_text,
41+
uint64_t Options::* field,
42+
OptionEnvvarSettings env_setting) {
43+
options_.emplace(
44+
name,
45+
OptionInfo{kUInteger,
46+
std::make_shared<SimpleOptionField<uint64_t>>(field),
47+
env_setting,
48+
help_text});
49+
}
50+
3851
template <typename Options>
3952
void OptionsParser<Options>::AddOption(const std::string& name,
4053
const std::string& help_text,
@@ -397,6 +410,9 @@ void OptionsParser<Options>::Parse(
397410
case kInteger:
398411
*Lookup<int64_t>(info.field, options) = std::atoll(value.c_str());
399412
break;
413+
case kUInteger:
414+
*Lookup<uint64_t>(info.field, options) = std::stoull(value.c_str());
415+
break;
400416
case kString:
401417
*Lookup<std::string>(info.field, options) = value;
402418
break;

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
412412
case kInteger:
413413
value = Number::New(isolate, *parser.Lookup<int64_t>(field, opts));
414414
break;
415+
case kUInteger:
416+
value = Number::New(isolate, *parser.Lookup<uint64_t>(field, opts));
417+
break;
415418
case kString:
416419
if (!ToV8Value(context, *parser.Lookup<std::string>(field, opts))
417420
.ToLocal(&value)) {
@@ -505,6 +508,7 @@ void Initialize(Local<Object> target,
505508
NODE_DEFINE_CONSTANT(types, kV8Option);
506509
NODE_DEFINE_CONSTANT(types, kBoolean);
507510
NODE_DEFINE_CONSTANT(types, kInteger);
511+
NODE_DEFINE_CONSTANT(types, kUInteger);
508512
NODE_DEFINE_CONSTANT(types, kString);
509513
NODE_DEFINE_CONSTANT(types, kHostPort);
510514
NODE_DEFINE_CONSTANT(types, kStringList);

src/node_options.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ enum OptionType {
168168
kV8Option,
169169
kBoolean,
170170
kInteger,
171+
kUInteger,
171172
kString,
172173
kHostPort,
173174
kStringList,
@@ -194,6 +195,10 @@ class OptionsParser {
194195
const std::string& help_text,
195196
bool Options::* field,
196197
OptionEnvvarSettings env_setting = kDisallowedInEnvironment);
198+
void AddOption(const std::string& name,
199+
const std::string& help_text,
200+
uint64_t Options::* field,
201+
OptionEnvvarSettings env_setting = kDisallowedInEnvironment);
197202
void AddOption(const std::string& name,
198203
const std::string& help_text,
199204
int64_t Options::* field,

0 commit comments

Comments
 (0)