"""CLI entry point for package."""importargparseimportloggingimportsysfromrun_iocsh.exceptionsimportRunIocshErrorfromrun_iocsh.iocimport(DEFAULT_DELAY,DEFAULT_EXECUTABLE,DEFAULT_EXIT_TIMEOUT,DEFAULT_FAIL_ON,run_iocsh,)
[docs]defparse_arguments(# noqa: D103args:list[str]|None=None,)->tuple[argparse.Namespace,list[str]]:parser=argparse.ArgumentParser(description="Run iocsh and send the exit command after <delay> seconds",formatter_class=argparse.ArgumentDefaultsHelpFormatter,)parser.add_argument("--delay",default=DEFAULT_DELAY,type=float,help="time (in seconds) to wait after iocInit before sending exit",)parser.add_argument("--timeout",default=DEFAULT_EXIT_TIMEOUT,type=float,help="time (in seconds) to wait for the IOC to exit after sending exit",)parser.add_argument("--executable",default=DEFAULT_EXECUTABLE,help="IOC executable to run",)parser.add_argument("--fail-on",action="append",dest="fail_on",default=[],metavar="PATTERN",help=("raise if regex PATTERN matches output; ^ERROR is always checked"" (may be given multiple times)"),)parser.add_argument("--no-default-fail-on",action="store_true",default=False,dest="no_default_fail_on",help="disable the always-active ^ERROR check",)returnparser.parse_known_args(args)
[docs]defmain()->None:# noqa: D103namespace,extra=parse_arguments()logging.basicConfig(format="%(asctime)s%(levelname)s: %(message)s ",level=logging.DEBUG)try:base=()ifnamespace.no_default_fail_onelseDEFAULT_FAIL_ONrun_iocsh(*extra,delay=namespace.delay,timeout=namespace.timeout,executable=namespace.executable,fail_on=base+tuple(namespace.fail_on),)except(RunIocshError,FileNotFoundError):log.exception("Found an error")sys.exit(1)