|
57 | 57 | type=str, |
58 | 58 | help='OpenSIPS MI FIFO Reply Directory') |
59 | 59 |
|
| 60 | +parser.add_argument('-bc', '--bash-complete', |
| 61 | + type=str, |
| 62 | + nargs='?', |
| 63 | + const='', |
| 64 | + help='Provide options for bash completion') |
| 65 | + |
60 | 66 | event = parser.add_argument_group('event') |
61 | 67 |
|
62 | 68 | event.add_argument('event', |
63 | 69 | type=str, |
| 70 | + nargs='?', |
64 | 71 | help='OpenSIPS Event Name') |
65 | 72 |
|
66 | 73 | event.add_argument('-T', '--transport', |
@@ -101,9 +108,43 @@ def main(): |
101 | 108 | elif args.type == 'datagram': |
102 | 109 | mi = OpenSIPSMI('datagram', |
103 | 110 | datagram_ip=args.ip, |
104 | | - datagram_port=args.port) |
| 111 | + datagram_port=args.port, |
| 112 | + timeout=0.1) |
105 | 113 | else: |
106 | | - print(f'Unknown type: {args.type}') |
| 114 | + if not args.bash_complete: |
| 115 | + print(f'Unknown type: {args.type}') |
| 116 | + sys.exit(1) |
| 117 | + |
| 118 | + if args.bash_complete is not None: |
| 119 | + if args.bash_complete != '': |
| 120 | + if len(args.bash_complete) > 1: |
| 121 | + last_arg = '--' + args.bash_complete |
| 122 | + else: |
| 123 | + last_arg = '-' + args.bash_complete |
| 124 | + |
| 125 | + for action in parser._actions: |
| 126 | + if last_arg in action.option_strings: |
| 127 | + if action.choices: |
| 128 | + print(' '.join(action.choices)) |
| 129 | + break |
| 130 | + sys.exit(0) |
| 131 | + else: |
| 132 | + options = [] |
| 133 | + for action in parser._actions: |
| 134 | + for opt in action.option_strings: |
| 135 | + options.append(opt) |
| 136 | + print(' '.join(options)) |
| 137 | + try: |
| 138 | + response = mi.execute('events_list', []) |
| 139 | + events = response.get("Events", []) |
| 140 | + event_names = [event["name"] for event in events] |
| 141 | + print(' '.join(event_names)) |
| 142 | + sys.exit(0) |
| 143 | + except Exception as e: |
| 144 | + sys.exit(1) |
| 145 | + |
| 146 | + if args.event is None: |
| 147 | + print('Event name is required') |
107 | 148 | sys.exit(1) |
108 | 149 |
|
109 | 150 | hdl = OpenSIPSEventHandler(mi, args.transport, |
|
0 commit comments