Skip to content

Commit ee51c90

Browse files
committed
tools/cli: add new args for cli
* `-d`/`--debug` global arg * subparser for command `update` * positional arg `hosts` for update command * optional arg `enablerepo` for update command * intermediate func for wrapping command Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent 29d7c8b commit ee51c90

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

lib/tools/cli.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,45 @@
33
The main entrypoint for running tools script.
44
"""
55
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+
615

716
def cli():
817
parser = argparse.ArgumentParser(
918
description="Tools that help developers for running recurrent tasks on their XCP-ng sandbox."
1019
)
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)
1146

12-
parser.parse_args()
47+
args.func(args)

0 commit comments

Comments
 (0)