MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / parse_args

Function parse_args

tests/benchmarks/big_db_test/big_db_test.py:211–254  ·  view source on GitHub ↗

Parse command-line options.

(argv)

Source from the content-addressed store, hash-verified

209
210
211def parse_args(argv) -> argparse.Namespace:
212 """Parse command-line options."""
213 p = argparse.ArgumentParser(
214 description="Feed the big_db_test project with simulated boards over UDP."
215 )
216 p.add_argument(
217 "--host", default="127.0.0.1", help="destination host (default: 127.0.0.1)"
218 )
219 p.add_argument(
220 "--port", type=int, default=8080, help="destination UDP port (default: 8080)"
221 )
222 p.add_argument(
223 "--rate",
224 type=float,
225 default=20.0,
226 help="per-board cycle rate in Hz (default: 20)",
227 )
228 p.add_argument(
229 "--cycles", type=int, default=0, help="stop after N cycles (0 = run forever)"
230 )
231 p.add_argument(
232 "--boards",
233 type=int,
234 default=BOARDS_PER_TYPE,
235 help="boards per type, 1..6 (default: 6)",
236 )
237 p.add_argument(
238 "--faults",
239 type=parse_fault_spec,
240 default={},
241 help="inject faults, e.g. 'TB:1:3,TA:2:5' (TYPE:board:channel)",
242 )
243 p.add_argument(
244 "--print",
245 dest="dump",
246 action="store_true",
247 help="print frames as hex, send nothing",
248 )
249 args = p.parse_args(argv)
250 if not 1 <= args.boards <= BOARDS_PER_TYPE:
251 p.error("--boards must be between 1 and 6")
252 if args.rate <= 0:
253 p.error("--rate must be positive")
254 return args
255
256
257def main(argv=None) -> int:

Callers 1

mainFunction · 0.70

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected