Skip to content

Commit c80ac7f

Browse files
mcollinaMylesBorins
authored andcommitted
src: add kUInteger parsing
This commit adds support for uint64_t option parsing. 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 0057af2 commit c80ac7f

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Diff for: lib/internal/print_help.js

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function getArgDescription(type) {
6969
case 'kHostPort':
7070
return '[host:]port';
7171
case 'kInteger':
72+
case 'kUInteger':
7273
case 'kString':
7374
case 'kStringList':
7475
return '...';

Diff for: src/node_options-inl.h

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ void OptionsParser<Options>::AddOption(const std::string& name,
3939
help_text});
4040
}
4141

42+
template <typename Options>
43+
void OptionsParser<Options>::AddOption(const std::string& name,
44+
const std::string& help_text,
45+
uint64_t Options::* field,
46+
OptionEnvvarSettings env_setting) {
47+
options_.emplace(
48+
name,
49+
OptionInfo{kUInteger,
50+
std::make_shared<SimpleOptionField<uint64_t>>(field),
51+
env_setting,
52+
help_text});
53+
}
54+
4255
template <typename Options>
4356
void OptionsParser<Options>::AddOption(const std::string& name,
4457
const std::string& help_text,
@@ -401,6 +414,9 @@ void OptionsParser<Options>::Parse(
401414
case kInteger:
402415
*Lookup<int64_t>(info.field, options) = std::atoll(value.c_str());
403416
break;
417+
case kUInteger:
418+
*Lookup<uint64_t>(info.field, options) = std::stoull(value.c_str());
419+
break;
404420
case kString:
405421
*Lookup<std::string>(info.field, options) = value;
406422
break;

Diff for: src/node_options.cc

+4
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
422422
case kInteger:
423423
value = Number::New(isolate, *parser.Lookup<int64_t>(field, opts));
424424
break;
425+
case kUInteger:
426+
value = Number::New(isolate, *parser.Lookup<uint64_t>(field, opts));
427+
break;
425428
case kString:
426429
if (!ToV8Value(context, *parser.Lookup<std::string>(field, opts))
427430
.ToLocal(&value)) {
@@ -509,6 +512,7 @@ void Initialize(Local<Object> target,
509512
NODE_DEFINE_CONSTANT(types, kV8Option);
510513
NODE_DEFINE_CONSTANT(types, kBoolean);
511514
NODE_DEFINE_CONSTANT(types, kInteger);
515+
NODE_DEFINE_CONSTANT(types, kUInteger);
512516
NODE_DEFINE_CONSTANT(types, kString);
513517
NODE_DEFINE_CONSTANT(types, kHostPort);
514518
NODE_DEFINE_CONSTANT(types, kStringList);

Diff for: src/node_options.h

+5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ enum OptionType {
203203
kV8Option,
204204
kBoolean,
205205
kInteger,
206+
kUInteger,
206207
kString,
207208
kHostPort,
208209
kStringList,
@@ -229,6 +230,10 @@ class OptionsParser {
229230
const std::string& help_text,
230231
bool Options::* field,
231232
OptionEnvvarSettings env_setting = kDisallowedInEnvironment);
233+
void AddOption(const std::string& name,
234+
const std::string& help_text,
235+
uint64_t Options::* field,
236+
OptionEnvvarSettings env_setting = kDisallowedInEnvironment);
232237
void AddOption(const std::string& name,
233238
const std::string& help_text,
234239
int64_t Options::* field,

0 commit comments

Comments
 (0)