Skip to content

Commit b40f465

Browse files
committed
feat(tools): adds 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 28a4b51 commit b40f465

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

lib/tools/cli.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,46 @@
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 xcpng 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+
# nargs="?",
37+
action="append",
38+
dest="repos",
39+
help="Enable one or more repositories",
40+
)
41+
subparser_cmd_update.set_defaults(func=_command_update)
42+
43+
args = parser.parse_args()
44+
45+
if args.debug:
46+
logger.setLevel(logging.DEBUG)
1147

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

0 commit comments

Comments
 (0)