diff --git a/trains_agent/interface/__init__.py b/trains_agent/interface/__init__.py index b698e1d..1242143 100644 --- a/trains_agent/interface/__init__.py +++ b/trains_agent/interface/__init__.py @@ -1,3 +1,4 @@ +import itertools from functools import partial from importlib import import_module import argparse @@ -24,8 +25,16 @@ def get_parser(): from .worker import COMMANDS subparsers = top_parser.add_subparsers(dest='command') for c in COMMANDS: - parser = subparsers.add_parser(name=c, help=COMMANDS[c]['help']) - for a in COMMANDS[c].get('args', {}).keys(): - parser.add_argument(a, **COMMANDS[c]['args'][a]) + parser = subparsers.add_parser(name=c, help=COMMANDS[c]["help"]) + groups = itertools.groupby( + sorted( + COMMANDS[c].get("args", {}).items(), key=lambda x: x[1].get("group", "") + ), + key=lambda x: x[1].pop("group", ""), + ) + for group_name, group in groups: + p = parser if not group_name else parser.add_argument_group(group_name) + for key, value in group: + p.add_argument(key, **value) return top_parser diff --git a/trains_agent/interface/worker.py b/trains_agent/interface/worker.py index c0202d6..bc49b8b 100644 --- a/trains_agent/interface/worker.py +++ b/trains_agent/interface/worker.py @@ -37,21 +37,29 @@ DAEMON_ARGS = dict({ 'help': 'Pipe full log to stdout/stderr, should not be used if running in background', 'action': 'store_true', }, - '--gpus': { - 'help': 'Specify active GPUs for the daemon to use (docker / virtual environment), ' - 'Equivalent to setting NVIDIA_VISIBLE_DEVICES ' - 'Examples: --gpus 0 or --gpu 0,1,2 or --gpus all', - }, - '--cpu-only': { - 'help': 'Disable GPU access for the daemon, only use CPU in either docker or virtual environment', - 'action': 'store_true', - }, '--docker': { 'help': 'Run execution task inside a docker (v19.03 and above). Optional args or ' 'specify default docker image in agent.default_docker.image / agent.default_docker.arguments' 'use --gpus/--cpu-only (or set NVIDIA_VISIBLE_DEVICES) to limit gpu visibility for docker', 'nargs': '*', 'default': False, + 'group': 'Docker support', + }, + '--gpus': { + 'help': 'Specify active GPUs for the daemon to use (docker / virtual environment), ' + 'Equivalent to setting NVIDIA_VISIBLE_DEVICES ' + 'Examples: --gpus 0 or --gpu 0,1,2 or --gpus all', + 'group': 'Docker support', + }, + '--cpu-only': { + 'help': 'Disable GPU access for the daemon, only use CPU in either docker or virtual environment', + 'action': 'store_true', + 'group': 'Docker support', + }, + '--force-current-version': { + 'help': 'Force trains-agent to use the current trains-agent version when running in the docker', + 'action': 'store_true', + 'group': 'Docker support', }, '--queue': { 'help': 'Queue ID(s)/Name(s) to pull tasks from (\'default\' queue)',