mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Improve ansible-test completion and messaging. (#19627)
* Simplify type annotation of args.docker_util. * Improve error messaging for ansible-doc test. * Add completion for docker, remote and windows.
This commit is contained in:
parent
6f5ecb7efd
commit
dac226de4a
5 changed files with 66 additions and 7 deletions
9
test/runner/completion/docker.txt
Normal file
9
test/runner/completion/docker.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
centos6
|
||||
centos7
|
||||
fedora-rawhide
|
||||
fedora23
|
||||
opensuseleap
|
||||
ubuntu1204
|
||||
ubuntu1404
|
||||
ubuntu1604
|
||||
ubuntu1604py3
|
3
test/runner/completion/remote.txt
Normal file
3
test/runner/completion/remote.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
freebsd/10.3-STABLE
|
||||
freebsd/11.0-STABLE
|
||||
osx/10.11
|
7
test/runner/completion/windows.txt
Normal file
7
test/runner/completion/windows.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
2008-SP2
|
||||
2008-R2_SP1
|
||||
2012-RTM
|
||||
2012-R2_RTM
|
||||
2016-English-Full-Base
|
||||
2016-English-Full-Containers
|
||||
2016-English-Nano-Base
|
|
@ -723,7 +723,7 @@ def command_sanity_ansible_doc(args, targets, python_version):
|
|||
stdout, stderr = intercept_command(args, cmd, env=env, capture=True, python_version=python_version)
|
||||
|
||||
if stderr:
|
||||
# consider any output on stderr an error, even though the return code is zero
|
||||
display.error('Output on stderr from ansible-doc is considered an error.')
|
||||
raise SubprocessError(cmd, stderr=stderr)
|
||||
|
||||
if stdout:
|
||||
|
@ -927,8 +927,8 @@ def detect_changes_local(args):
|
|||
|
||||
def docker_qualify_image(name):
|
||||
"""
|
||||
:type name: str | None
|
||||
:rtype: str | None
|
||||
:type name: str
|
||||
:rtype: str
|
||||
"""
|
||||
if not name or any((c in name) for c in ('/', ':')):
|
||||
return name
|
||||
|
@ -1105,7 +1105,7 @@ class EnvironmentConfig(CommonConfig):
|
|||
self.remote = args.remote # type: str
|
||||
|
||||
self.docker_privileged = args.docker_privileged if 'docker_privileged' in args else False # type: bool
|
||||
self.docker_util = docker_qualify_image(args.docker_util if 'docker_util' in args else None) # type: str | None
|
||||
self.docker_util = docker_qualify_image(args.docker_util if 'docker_util' in args else '') # type: str
|
||||
self.docker_pull = args.docker_pull if 'docker_pull' in args else False # type: bool
|
||||
|
||||
self.tox_sitepackages = args.tox_sitepackages # type: bool
|
||||
|
|
|
@ -205,7 +205,7 @@ def parse_args():
|
|||
windows_integration.add_argument('--windows',
|
||||
metavar='VERSION',
|
||||
action='append',
|
||||
help='windows version')
|
||||
help='windows version').completer = complete_windows
|
||||
|
||||
units = subparsers.add_parser('units',
|
||||
parents=[test],
|
||||
|
@ -413,12 +413,12 @@ def add_environments(parser, tox_version=False, tox_only=False):
|
|||
nargs='?',
|
||||
default=None,
|
||||
const='ubuntu1604',
|
||||
help='run from a docker container')
|
||||
help='run from a docker container').completer = complete_docker
|
||||
|
||||
environments.add_argument('--remote',
|
||||
metavar='PLATFORM',
|
||||
default=None,
|
||||
help='run from a remote instance')
|
||||
help='run from a remote instance').completer = complete_remote
|
||||
|
||||
remote = parser.add_argument_group(title='remote arguments')
|
||||
|
||||
|
@ -463,5 +463,45 @@ def complete_target(prefix, parsed_args, **_):
|
|||
return find_target_completion(parsed_args.targets, prefix)
|
||||
|
||||
|
||||
def complete_remote(prefix, parsed_args, **_):
|
||||
"""
|
||||
:type prefix: unicode
|
||||
:type parsed_args: any
|
||||
:rtype: list[str]
|
||||
"""
|
||||
del parsed_args
|
||||
|
||||
with open('test/runner/completion/remote.txt', 'r') as completion_fd:
|
||||
images = completion_fd.read().splitlines()
|
||||
|
||||
return [i for i in images if i.startswith(prefix)]
|
||||
|
||||
|
||||
def complete_docker(prefix, parsed_args, **_):
|
||||
"""
|
||||
:type prefix: unicode
|
||||
:type parsed_args: any
|
||||
:rtype: list[str]
|
||||
"""
|
||||
del parsed_args
|
||||
|
||||
with open('test/runner/completion/docker.txt', 'r') as completion_fd:
|
||||
images = completion_fd.read().splitlines()
|
||||
|
||||
return [i for i in images if i.startswith(prefix)]
|
||||
|
||||
|
||||
def complete_windows(prefix, parsed_args, **_):
|
||||
"""
|
||||
:type prefix: unicode
|
||||
:type parsed_args: any
|
||||
:rtype: list[str]
|
||||
"""
|
||||
with open('test/runner/completion/windows.txt', 'r') as completion_fd:
|
||||
images = completion_fd.read().splitlines()
|
||||
|
||||
return [i for i in images if i.startswith(prefix) and (not parsed_args.windows or i not in parsed_args.windows)]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue