Parse command-line arguments.
()
| 308 | |
| 309 | |
| 310 | def parse_arguments(): |
| 311 | """Parse command-line arguments.""" |
| 312 | parser = argparse.ArgumentParser( |
| 313 | description="Mirix Load Test - Add messages to the Mirix system", |
| 314 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 315 | epilog=""" |
| 316 | Examples: |
| 317 | %(prog)s # Add 100 messages (default) |
| 318 | %(prog)s 500 # Add 500 messages |
| 319 | %(prog)s 4159 # Add all available messages |
| 320 | %(prog)s --count 1000 # Add 1000 messages (using flag) |
| 321 | """, |
| 322 | ) |
| 323 | |
| 324 | parser.add_argument( |
| 325 | "count", |
| 326 | nargs="?", |
| 327 | type=int, |
| 328 | default=LoadTestConfig.DEFAULT_MESSAGE_COUNT, |
| 329 | help="Number of messages to add (1-{}, default: {})".format( |
| 330 | LoadTestConfig.MAX_AVAILABLE_MESSAGES, LoadTestConfig.DEFAULT_MESSAGE_COUNT |
| 331 | ), |
| 332 | ) |
| 333 | |
| 334 | parser.add_argument( |
| 335 | "--batch-size", |
| 336 | type=int, |
| 337 | default=LoadTestConfig.BATCH_SIZE, |
| 338 | help=f"Number of messages per batch (default: {LoadTestConfig.BATCH_SIZE})", |
| 339 | ) |
| 340 | |
| 341 | parser.add_argument( |
| 342 | "--delay", |
| 343 | type=float, |
| 344 | default=LoadTestConfig.DELAY_BETWEEN_BATCHES, |
| 345 | help=f"Delay between batches in seconds (default: {LoadTestConfig.DELAY_BETWEEN_BATCHES})", |
| 346 | ) |
| 347 | |
| 348 | args = parser.parse_args() |
| 349 | |
| 350 | # Validate count |
| 351 | if args.count < 1: |
| 352 | parser.error("count must be at least 1") |
| 353 | if args.count > LoadTestConfig.MAX_AVAILABLE_MESSAGES: |
| 354 | parser.error( |
| 355 | "count cannot exceed {} (maximum available messages)".format(LoadTestConfig.MAX_AVAILABLE_MESSAGES) |
| 356 | ) |
| 357 | |
| 358 | # Validate batch size |
| 359 | if args.batch_size < 1: |
| 360 | parser.error("batch-size must be at least 1") |
| 361 | |
| 362 | # Validate delay |
| 363 | if args.delay < 0: |
| 364 | parser.error("delay cannot be negative") |
| 365 | |
| 366 | return args |
| 367 |