"""Command line interface for hbd package.""" import argparse from .config import load_config from .main import run as run_server PUSHSRVS = ["all", "pushover", "mattermost"] def build_parser(): parser = argparse.ArgumentParser( prog="hbd", description="HeartBeatDaemon - Wait for heartbeat messages and act on them (or their absence)", formatter_class=argparse.RawDescriptionHelpFormatter, ) parser.add_argument( "-c", "--config", dest="configfile", help="Config file path (YAML)" ) parser.add_argument( "-f", "--foreground", action="store_true", help="Run in foreground" ) parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output") parser.add_argument( "-p", "--pushsrv", dest="pushsrv", choices=PUSHSRVS, help="Push service to use" ) parser.add_argument( "-x", "--debug", action="count", default=0, help="Increase debug level" ) return parser def main(argv=None): parser = build_parser() args = parser.parse_args(argv) config = load_config(args.configfile) # Apply CLI overrides if args.foreground: config["foreground"] = True if args.verbose: config["verbose"] = True if args.pushsrv: config["pushsrv"] = args.pushsrv if args.debug > 0: config["debug"] = args.debug run_server(config) if __name__ == "__main__": main()