@@ -185,42 +185,40 @@ class CLIParser
185185 }
186186 else if (arg == " --max-bytes" )
187187 {
188- if (config.entity = = CLIParser::EntityKind::PUBLISHER )
188+ if (config.entity ! = CLIParser::EntityKind::PUBLISHER )
189189 {
190- if (++i < argc)
190+ EPROSIMA_LOG_ERROR (CLI_PARSER , " max-bytes argument is only valid for publisher entity" );
191+ print_help (EXIT_FAILURE );
192+ }
193+
194+ if (++i < argc)
195+ {
196+ try
191197 {
192- try
193- {
194- unsigned long input = std::stoul (argv[i]);
195-
196- if (input > static_cast <unsigned long >(std::numeric_limits<int32_t >::max ()))
197- {
198- throw std::out_of_range (" max-bytes argument " + std::string (
199- argv[i]) + " out of range [0, 2147483647]." );
200- }
201- config.max_bytes_per_period = static_cast <int32_t >(input);
202- }
203- catch (const std::invalid_argument& e)
204- {
205- EPROSIMA_LOG_ERROR (CLI_PARSER , " invalid max-bytes argument " + std::string (
206- argv[i]) + " : " + std::string (e.what ()));
207- print_help (EXIT_FAILURE );
208- }
209- catch (const std::out_of_range& e)
198+ unsigned long input = std::stoul (argv[i]);
199+
200+ if (input > static_cast <unsigned long >(std::numeric_limits<int32_t >::max ()))
210201 {
211- EPROSIMA_LOG_ERROR ( CLI_PARSER , std::string (e. what ()));
212- print_help ( EXIT_FAILURE );
202+ throw std::out_of_range ( " max-bytes argument " + std::string (
203+ argv[i]) + " out of range [0, 2147483647]. " );
213204 }
205+ config.max_bytes_per_period = static_cast <int32_t >(input);
214206 }
215- else
207+ catch (const std::invalid_argument& e)
208+ {
209+ EPROSIMA_LOG_ERROR (CLI_PARSER , " invalid max-bytes argument " + std::string (
210+ argv[i]) + " : " + std::string (e.what ()));
211+ print_help (EXIT_FAILURE );
212+ }
213+ catch (const std::out_of_range& e)
216214 {
217- EPROSIMA_LOG_ERROR (CLI_PARSER , " parsing max-bytes argument " );
215+ EPROSIMA_LOG_ERROR (CLI_PARSER , std::string (e. what ()) );
218216 print_help (EXIT_FAILURE );
219217 }
220218 }
221219 else
222220 {
223- EPROSIMA_LOG_ERROR (CLI_PARSER , " max-bytes argument is only valid for publisher entity " );
221+ EPROSIMA_LOG_ERROR (CLI_PARSER , " parsing max-bytes argument" );
224222 print_help (EXIT_FAILURE );
225223 }
226224 }
@@ -236,25 +234,14 @@ class CLIParser
236234 {
237235 try
238236 {
239- uint64_t input = std::stoull (argv[i]);
240- if (input > std::numeric_limits<uint64_t >::max ())
241- {
242- throw std::out_of_range (" period argument " + std::string (
243- argv[i]) + " out of range." );
244- }
245- config.period = input;
237+ config.period = std::stoull (argv[i]);
246238 }
247239 catch (const std::invalid_argument& e)
248240 {
249241 EPROSIMA_LOG_ERROR (CLI_PARSER , " invalid period argument " + std::string (
250242 argv[i]) + " : " + std::string (e.what ()));
251243 print_help (EXIT_FAILURE );
252244 }
253- catch (const std::out_of_range& e)
254- {
255- EPROSIMA_LOG_ERROR (CLI_PARSER , std::string (e.what ()));
256- print_help (EXIT_FAILURE );
257- }
258245 }
259246 else
260247 {
@@ -265,38 +252,38 @@ class CLIParser
265252 }
266253 else if (arg == " --scheduler" )
267254 {
255+ if (config.entity != CLIParser::EntityKind::PUBLISHER )
256+ {
257+ EPROSIMA_LOG_ERROR (CLI_PARSER , " scheduler argument is only valid for publisher entity" );
258+ print_help (EXIT_FAILURE );
259+ }
260+
268261 if (++i < argc)
269262 {
270263 std::string scheduler = argv[i];
271- if (config.entity == CLIParser::EntityKind::PUBLISHER )
264+
265+ if (scheduler == " FIFO" )
272266 {
273- if (scheduler == " FIFO" )
274- {
275- config.scheduler = rtps::FlowControllerSchedulerPolicy::FIFO ;
276- }
277- else if (scheduler == " ROUND-ROBIN" )
278- {
279- config.scheduler = rtps::FlowControllerSchedulerPolicy::ROUND_ROBIN ;
280- }
281- else if (scheduler == " HIGH-PRIORITY" )
282- {
283- config.scheduler = rtps::FlowControllerSchedulerPolicy::HIGH_PRIORITY ;
284- }
285- else if (scheduler == " PRIORITY-RESERVATION" )
286- {
287- config.scheduler = rtps::FlowControllerSchedulerPolicy::PRIORITY_WITH_RESERVATION ;
288- }
289- else
290- {
291- EPROSIMA_LOG_ERROR (CLI_PARSER , " unknown argument " );
292- print_help (EXIT_FAILURE );
293- }
267+ config.scheduler = rtps::FlowControllerSchedulerPolicy::FIFO ;
268+ }
269+ else if (scheduler == " ROUND-ROBIN" )
270+ {
271+ config.scheduler = rtps::FlowControllerSchedulerPolicy::ROUND_ROBIN ;
272+ }
273+ else if (scheduler == " HIGH-PRIORITY" )
274+ {
275+ config.scheduler = rtps::FlowControllerSchedulerPolicy::HIGH_PRIORITY ;
276+ }
277+ else if (scheduler == " PRIORITY-RESERVATION" )
278+ {
279+ config.scheduler = rtps::FlowControllerSchedulerPolicy::PRIORITY_WITH_RESERVATION ;
294280 }
295281 else
296282 {
297- EPROSIMA_LOG_ERROR (CLI_PARSER , " scheduler argument is only valid for publisher entity " );
283+ EPROSIMA_LOG_ERROR (CLI_PARSER , " unknown argument " );
298284 print_help (EXIT_FAILURE );
299285 }
286+
300287 }
301288 else
302289 {
@@ -306,6 +293,12 @@ class CLIParser
306293 }
307294 else if (arg == " --bandwidth" )
308295 {
296+ if (config.entity != CLIParser::EntityKind::PUBLISHER )
297+ {
298+ EPROSIMA_LOG_ERROR (CLI_PARSER , " bandwidth argument is only valid for publisher entity" );
299+ print_help (EXIT_FAILURE );
300+ }
301+
309302 if (++i < argc)
310303 {
311304 try
@@ -317,15 +310,7 @@ class CLIParser
317310 argv[i]) + " out of range." );
318311 }
319312
320- if (config.entity == CLIParser::EntityKind::PUBLISHER )
321- {
322- config.bandwidth = argv[i];
323- }
324- else
325- {
326- EPROSIMA_LOG_ERROR (CLI_PARSER , " bandwidth argument is only valid for publisher entity" );
327- print_help (EXIT_FAILURE );
328- }
313+ config.bandwidth = argv[i];
329314 }
330315 catch (const std::invalid_argument& e)
331316 {
@@ -347,6 +332,12 @@ class CLIParser
347332 }
348333 else if (arg == " --priority" )
349334 {
335+ if (config.entity != CLIParser::EntityKind::PUBLISHER )
336+ {
337+ EPROSIMA_LOG_ERROR (CLI_PARSER , " priority argument is only valid for publisher entity" );
338+ print_help (EXIT_FAILURE );
339+ }
340+
350341 if (++i < argc)
351342 {
352343 try
@@ -358,15 +349,7 @@ class CLIParser
358349 argv[i]) + " out of range." );
359350 }
360351
361- if (config.entity == CLIParser::EntityKind::PUBLISHER )
362- {
363- config.priority = argv[i];
364- }
365- else
366- {
367- EPROSIMA_LOG_ERROR (CLI_PARSER , " priority argument is only valid for publisher entity" );
368- print_help (EXIT_FAILURE );
369- }
352+ config.priority = argv[i];
370353 }
371354 catch (const std::invalid_argument& e)
372355 {
0 commit comments