Skip to content

Commit

Permalink
Use default_value_if() + required instead of the manual hack
Browse files Browse the repository at this point in the history
  • Loading branch information
steviez committed Mar 12, 2024
1 parent 78645b7 commit b9e7173
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
7 changes: 6 additions & 1 deletion validator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,15 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
.arg(
Arg::with_name("rpc_pubsub_notification_threads")
.long("rpc-pubsub-notification-threads")
.requires("full_rpc_api")
.takes_value(true)
.value_name("NUM_THREADS")
.validator(is_parsable::<usize>)
.default_value(&default_args.rpc_pubsub_notification_threads)
.default_value_if(
"full_rpc_api",
None,
&default_args.rpc_pubsub_notification_threads,
)
.help(
"The maximum number of threads that RPC PubSub will use for generating \
notifications. 0 will disable RPC PubSub notifications",
Expand Down
19 changes: 3 additions & 16 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,22 +1382,9 @@ pub fn main() {
usize
),
worker_threads: value_t_or_exit!(matches, "rpc_pubsub_worker_threads", usize),
notification_threads: if full_api {
NonZeroUsize::new(value_t_or_exit!(
matches,
"rpc_pubsub_notification_threads",
usize
))
} else {
// Due to a CLAP bug, we can't use .requires("full_rpc_api") directly on
// the rpc_pubsub_notification_threads argument. Do the check manually here,
// and remove this when we get past 2.xy of CLAP
if matches.occurrences_of("rpc_pubsub_notification_threads") > 0 {
eprintln!("Use of --rpc_pubsub_notification_threads requires --full-rpc-api");
exit(1);
}
None
},
notification_threads: value_t!(matches, "rpc_pubsub_notification_threads", usize)
.ok()
.and_then(NonZeroUsize::new),
},
voting_disabled: matches.is_present("no_voting") || restricted_repair_only_mode,
wait_for_supermajority: value_t!(matches, "wait_for_supermajority", Slot).ok(),
Expand Down

0 comments on commit b9e7173

Please sign in to comment.