|
31 | 31 | import sys
|
32 | 32 | import threading
|
33 | 33 | import logging
|
| 34 | +import argparse |
34 | 35 |
|
35 | 36 | logging.basicConfig()
|
36 | 37 |
|
@@ -473,32 +474,28 @@ def example_list(a, args):
|
473 | 474 |
|
474 | 475 |
|
475 | 476 | def parse_list_consumer_groups_args(args, states, types):
|
| 477 | + parser = argparse.ArgumentParser(prog='list_consumer_groups') |
| 478 | + parser.add_argument('-states') |
| 479 | + parser.add_argument('-types') |
| 480 | + parsed_args = parser.parse_args(args) |
| 481 | + |
476 | 482 | def usage(message):
|
477 |
| - raise Exception(f"{message}\nUsage: list_consumer_groups [-states <state1> <state2> ..] " |
478 |
| - "[-types <type1> <type2> ..]") |
479 |
| - |
480 |
| - if len(args) > 0: |
481 |
| - typeArray = False |
482 |
| - stateArray = False |
483 |
| - lastArray = 0 |
484 |
| - for i in range(0, len(args)): |
485 |
| - if (args[i] == "-states"): |
486 |
| - if (stateArray): |
487 |
| - usage("Cannot pass the states flag (-states) more than once") |
488 |
| - lastArray = 1 |
489 |
| - stateArray = True |
490 |
| - elif (args[i] == "-types"): |
491 |
| - if (typeArray): |
492 |
| - usage("Cannot pass the types flag (-types) more than once") |
493 |
| - lastArray = 2 |
494 |
| - typeArray = True |
495 |
| - else: |
496 |
| - if (lastArray == 1): |
497 |
| - states.add(ConsumerGroupState[args[i]]) |
498 |
| - elif (lastArray == 2): |
499 |
| - types.add(ConsumerGroupType[args[i]]) |
500 |
| - else: |
501 |
| - usage(f"Unknown argument: {args[i]}") |
| 483 | + print(message) |
| 484 | + parser.print_usage() |
| 485 | + sys.exit(1) |
| 486 | + |
| 487 | + if parsed_args.states: |
| 488 | + for arg in parsed_args.states.split(","): |
| 489 | + try: |
| 490 | + states.add(ConsumerGroupState[arg]) |
| 491 | + except KeyError: |
| 492 | + usage(f"Invalid state: {arg}") |
| 493 | + if parsed_args.types: |
| 494 | + for arg in parsed_args.types.split(","): |
| 495 | + try: |
| 496 | + types.add(ConsumerGroupType[arg]) |
| 497 | + except KeyError: |
| 498 | + usage(f"Invalid type: {arg}") |
502 | 499 |
|
503 | 500 |
|
504 | 501 | def example_list_consumer_groups(a, args):
|
@@ -934,7 +931,8 @@ def example_delete_records(a, args):
|
934 | 931 | sys.stderr.write(' delete_acls <resource_type1> <resource_name1> <resource_patter_type1> ' +
|
935 | 932 | '<principal1> <host1> <operation1> <permission_type1> ..\n')
|
936 | 933 | sys.stderr.write(' list [<all|topics|brokers|groups>]\n')
|
937 |
| - sys.stderr.write(' list_consumer_groups [<state1> <state2> ..]\n') |
| 934 | + sys.stderr.write(' list_consumer_groups [-states <state1>,<state2>,..] ' + |
| 935 | + '[-types <type1>,<type2>,..]\n') |
938 | 936 | sys.stderr.write(' describe_consumer_groups <include_authorized_operations> <group1> <group2> ..\n')
|
939 | 937 | sys.stderr.write(' describe_topics <include_authorized_operations> <topic1> <topic2> ..\n')
|
940 | 938 | sys.stderr.write(' describe_cluster <include_authorized_operations>\n')
|
|
0 commit comments