|
| 1 | +"""CLI Entrypoint |
| 2 | +
|
| 3 | +The main entrypoint for running tools script. |
| 4 | +""" |
| 5 | +import argparse |
| 6 | +import logging |
| 7 | + |
| 8 | +from lib.common import HostAddress |
| 9 | +from lib.tools import logger |
| 10 | +from lib.tools.tasks.update import update_all |
| 11 | + |
| 12 | +def _command_update(args): |
| 13 | + update_all(args.hosts, args.repos) |
| 14 | + |
| 15 | + |
| 16 | +def cli(): |
| 17 | + parser = argparse.ArgumentParser( |
| 18 | + description="Tools that help developers for running recurrent tasks on their XCP-ng sandbox." |
| 19 | + ) |
| 20 | + parser.add_argument("-d", "--debug", action="store_true", default=False, help="Enable debug level") |
| 21 | + |
| 22 | + subparsers = parser.add_subparsers(required=True, metavar="COMMAND") |
| 23 | + |
| 24 | + # subparser - command: update |
| 25 | + subparser_cmd_update = subparsers.add_parser( |
| 26 | + name="update", |
| 27 | + description="Run update tasks on target(s)", |
| 28 | + help="Run update tasks on target(s)", |
| 29 | + ) |
| 30 | + subparser_cmd_update.add_argument( |
| 31 | + "hosts", type=HostAddress, metavar="HOST", nargs="+", help="Hostname(s) or ip address(es) of target(s)" |
| 32 | + ) |
| 33 | + subparser_cmd_update.add_argument( |
| 34 | + "--enablerepo", |
| 35 | + metavar="REPO", |
| 36 | + action="append", |
| 37 | + dest="repos", |
| 38 | + help="repositories to enable when updating", |
| 39 | + ) |
| 40 | + subparser_cmd_update.set_defaults(func=_command_update) |
| 41 | + |
| 42 | + args = parser.parse_args() |
| 43 | + |
| 44 | + if args.debug: |
| 45 | + logger.setLevel(logging.DEBUG) |
| 46 | + |
| 47 | + args.func(args) |
0 commit comments