mirror of
https://github.com/docker/compose.git
synced 2025-07-28 16:14:06 +02:00
Merge pull request #8061 from albers/completion-profiles
Add bash completion for profiles and a command to list profiles
This commit is contained in:
commit
84afa518e8
@ -390,6 +390,7 @@ class TopLevelCommand:
|
|||||||
--no-interpolate Don't interpolate environment variables.
|
--no-interpolate Don't interpolate environment variables.
|
||||||
-q, --quiet Only validate the configuration, don't print
|
-q, --quiet Only validate the configuration, don't print
|
||||||
anything.
|
anything.
|
||||||
|
--profiles Print the profile names, one per line.
|
||||||
--services Print the service names, one per line.
|
--services Print the service names, one per line.
|
||||||
--volumes Print the volume names, one per line.
|
--volumes Print the volume names, one per line.
|
||||||
--hash="*" Print the service config hash, one per line.
|
--hash="*" Print the service config hash, one per line.
|
||||||
@ -409,6 +410,15 @@ class TopLevelCommand:
|
|||||||
if options['--quiet']:
|
if options['--quiet']:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if options['--profiles']:
|
||||||
|
profiles = set()
|
||||||
|
for service in compose_config.services:
|
||||||
|
if 'profiles' in service:
|
||||||
|
for profile in service['profiles']:
|
||||||
|
profiles.add(profile)
|
||||||
|
print('\n'.join(sorted(profiles)))
|
||||||
|
return
|
||||||
|
|
||||||
if options['--services']:
|
if options['--services']:
|
||||||
print('\n'.join(service['name'] for service in compose_config.services))
|
print('\n'.join(service['name'] for service in compose_config.services))
|
||||||
return
|
return
|
||||||
|
@ -138,7 +138,7 @@ _docker_compose_config() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
COMPREPLY=( $( compgen -W "--hash --help --no-interpolate --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--hash --help --no-interpolate --profiles --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -172,6 +172,10 @@ _docker_compose_docker_compose() {
|
|||||||
COMPREPLY=( $( compgen -W "debug info warning error critical" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "debug info warning error critical" -- "$cur" ) )
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
--profile)
|
||||||
|
COMPREPLY=( $( compgen -W "$(__docker_compose_q config --profiles)" -- "$cur" ) )
|
||||||
|
return
|
||||||
|
;;
|
||||||
--project-directory)
|
--project-directory)
|
||||||
_filedir -d
|
_filedir -d
|
||||||
return
|
return
|
||||||
@ -618,10 +622,11 @@ _docker_compose() {
|
|||||||
--tlskey
|
--tlskey
|
||||||
"
|
"
|
||||||
|
|
||||||
# These options are require special treatment when searching the command.
|
# These options require special treatment when searching the command.
|
||||||
local top_level_options_with_args="
|
local top_level_options_with_args="
|
||||||
--ansi
|
--ansi
|
||||||
--log-level
|
--log-level
|
||||||
|
--profile
|
||||||
"
|
"
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
|
@ -237,6 +237,11 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1)
|
result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1)
|
||||||
assert "Couldn't connect to Docker daemon" in result.stderr
|
assert "Couldn't connect to Docker daemon" in result.stderr
|
||||||
|
|
||||||
|
def test_config_list_profiles(self):
|
||||||
|
self.base_dir = 'tests/fixtures/config-profiles'
|
||||||
|
result = self.dispatch(['config', '--profiles'])
|
||||||
|
assert set(result.stdout.rstrip().split('\n')) == {'debug', 'frontend', 'gui'}
|
||||||
|
|
||||||
def test_config_list_services(self):
|
def test_config_list_services(self):
|
||||||
self.base_dir = 'tests/fixtures/v2-full'
|
self.base_dir = 'tests/fixtures/v2-full'
|
||||||
result = self.dispatch(['config', '--services'])
|
result = self.dispatch(['config', '--services'])
|
||||||
|
15
tests/fixtures/config-profiles/docker-compose.yml
vendored
Normal file
15
tests/fixtures/config-profiles/docker-compose.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
frontend:
|
||||||
|
image: frontend
|
||||||
|
profiles: ["frontend", "gui"]
|
||||||
|
phpmyadmin:
|
||||||
|
image: phpmyadmin
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
profiles:
|
||||||
|
- debug
|
||||||
|
backend:
|
||||||
|
image: backend
|
||||||
|
db:
|
||||||
|
image: mysql
|
Loading…
x
Reference in New Issue
Block a user