@@ -18,8 +18,8 @@ namespace Client {
1818OptionsImpl::OptionsImpl (int argc, const char * const * argv) {
1919 setNonTrivialDefaults ();
2020 // Override some defaults, we are in CLI-mode.
21- verbosity_ = " info " ;
22- output_format_ = " human " ;
21+ verbosity_ = nighthawk::client::Verbosity::INFO ;
22+ output_format_ = nighthawk::client::OutputFormat::HUMAN ;
2323
2424 // TODO(oschaaf): Purge the validation we perform here. Most of it should have become
2525 // redundant now that we also perform validation of the resulting proto.
@@ -99,7 +99,7 @@ OptionsImpl::OptionsImpl(int argc, const char* const* argv) {
9999 " " , " address-family" ,
100100 fmt::format (" Network addres family preference. Possible values: [auto, v4, v6]. The "
101101 " default output format is '{}'." ,
102- address_family_),
102+ nighthawk::client::AddressFamily::AddressFamilyOptions_Name ( address_family_) ),
103103 false , " " , &address_families_allowed, cmd);
104104
105105 std::vector<std::string> request_methods = {" GET" , " HEAD" , " POST" , " PUT" ,
@@ -166,18 +166,47 @@ OptionsImpl::OptionsImpl(int argc, const char* const* argv) {
166166 uri_ = uri.getValue ();
167167 TCLAP_SET_IF_SPECIFIED (h2, h2_);
168168 TCLAP_SET_IF_SPECIFIED (concurrency, concurrency_);
169- TCLAP_SET_IF_SPECIFIED (verbosity, verbosity_);
170- TCLAP_SET_IF_SPECIFIED (output_format, output_format_);
169+ // TODO(oschaaf): is there a generic way to set these enum values?
170+ if (verbosity.isSet ()) {
171+ std::string upper_cased = verbosity.getValue ();
172+ absl::AsciiStrToUpper (&upper_cased);
173+ RELEASE_ASSERT (nighthawk::client::Verbosity::VerbosityOptions_Parse (upper_cased, &verbosity_),
174+ " Failed to parse verbosity" );
175+ }
176+ if (output_format.isSet ()) {
177+ std::string upper_cased = output_format.getValue ();
178+ absl::AsciiStrToUpper (&upper_cased);
179+ RELEASE_ASSERT (
180+ nighthawk::client::OutputFormat::OutputFormatOptions_Parse (upper_cased, &output_format_),
181+ " Failed to parse output format" );
182+ }
171183 TCLAP_SET_IF_SPECIFIED (prefetch_connections, prefetch_connections_);
172184 TCLAP_SET_IF_SPECIFIED (burst_size, burst_size_);
173- TCLAP_SET_IF_SPECIFIED (address_family, address_family_);
174- TCLAP_SET_IF_SPECIFIED (request_method, request_method_);
185+ if (address_family.isSet ()) {
186+ std::string upper_cased = address_family.getValue ();
187+ absl::AsciiStrToUpper (&upper_cased);
188+ RELEASE_ASSERT (
189+ nighthawk::client::AddressFamily::AddressFamilyOptions_Parse (upper_cased, &address_family_),
190+ " Failed to parse address family" );
191+ }
192+ if (request_method.isSet ()) {
193+ std::string upper_cased = request_method.getValue ();
194+ absl::AsciiStrToUpper (&upper_cased);
195+ RELEASE_ASSERT (envoy::api::v2::core::RequestMethod_Parse (upper_cased, &request_method_),
196+ " Failed to parse request method" );
197+ }
175198 TCLAP_SET_IF_SPECIFIED (request_headers, request_headers_);
176199 TCLAP_SET_IF_SPECIFIED (request_body_size, request_body_size_);
177200 TCLAP_SET_IF_SPECIFIED (max_pending_requests, max_pending_requests_);
178201 TCLAP_SET_IF_SPECIFIED (max_active_requests, max_active_requests_);
179202 TCLAP_SET_IF_SPECIFIED (max_requests_per_connection, max_requests_per_connection_);
180- TCLAP_SET_IF_SPECIFIED (sequencer_idle_strategy, sequencer_idle_strategy_);
203+ if (sequencer_idle_strategy.isSet ()) {
204+ std::string upper_cased = sequencer_idle_strategy.getValue ();
205+ absl::AsciiStrToUpper (&upper_cased);
206+ RELEASE_ASSERT (nighthawk::client::SequencerIdleStrategy::SequencerIdleStrategyOptions_Parse (
207+ upper_cased, &sequencer_idle_strategy_),
208+ " Failed to parse sequencer idle strategy" );
209+ }
181210
182211 // CLI-specific tests.
183212 // TODO(oschaaf): as per mergconflicts's remark, it would be nice to aggregate
@@ -247,10 +276,11 @@ OptionsImpl::OptionsImpl(const nighthawk::client::CommandLineOptions& options) {
247276 PROTOBUF_GET_WRAPPED_OR_DEFAULT (options, prefetch_connections, prefetch_connections_);
248277 burst_size_ = PROTOBUF_GET_WRAPPED_OR_DEFAULT (options, burst_size, burst_size_);
249278 address_family_ = PROTOBUF_GET_WRAPPED_OR_DEFAULT (options, address_family, address_family_);
279+
250280 const auto & request_options = options.request_options ();
251281 if (request_options.request_method () !=
252282 ::envoy::api::v2::core::RequestMethod::METHOD_UNSPECIFIED) {
253- request_method_ = :: envoy::api::v2::core::RequestMethod_Name ( request_options.request_method () );
283+ request_method_ = request_options.request_method ();
254284 }
255285 request_body_size_ =
256286 PROTOBUF_GET_WRAPPED_OR_DEFAULT (request_options, request_body_size, request_body_size_);
@@ -268,14 +298,7 @@ OptionsImpl::OptionsImpl(const nighthawk::client::CommandLineOptions& options) {
268298 validate ();
269299}
270300
271- void OptionsImpl::setNonTrivialDefaults () {
272- concurrency_ = " 1" ;
273- verbosity_ = " warn" ;
274- output_format_ = " json" ;
275- address_family_ = " v4" ;
276- request_method_ = " GET" ;
277- sequencer_idle_strategy_ = " spin" ;
278- }
301+ void OptionsImpl::setNonTrivialDefaults () { concurrency_ = " 1" ; }
279302
280303void OptionsImpl::validate () const {
281304 // concurrency must be either 'auto' or a positive integer.
@@ -319,12 +342,10 @@ CommandLineOptionsPtr OptionsImpl::toCommandLineOptions() const {
319342 command_line_options->mutable_output_format ()->set_value (outputFormat ());
320343 command_line_options->mutable_prefetch_connections ()->set_value (prefetchConnections ());
321344 command_line_options->mutable_burst_size ()->set_value (burstSize ());
322- command_line_options->mutable_address_family ()->set_value (addressFamily ());
345+ command_line_options->mutable_address_family ()->set_value (
346+ static_cast <nighthawk::client::AddressFamily_AddressFamilyOptions>(addressFamily ()));
323347 auto request_options = command_line_options->mutable_request_options ();
324- envoy::api::v2::core::RequestMethod method =
325- envoy::api::v2::core::RequestMethod::METHOD_UNSPECIFIED;
326- envoy::api::v2::core::RequestMethod_Parse (requestMethod (), &method);
327- request_options->set_request_method (method);
348+ request_options->set_request_method (requestMethod ());
328349 for (const auto & header : requestHeaders ()) {
329350 auto header_value_option = request_options->add_request_headers ();
330351 // TODO(oschaaf): expose append option in CLI? For now we just set.
0 commit comments