CLI: Add --detach option for up, run and exec commands

This contribution allows the usage of --detach option when running:

docker-compose run --detach
docker-compose exec --detach
docker-compose up --detach

The behavior is the same as the -d option.

Signed-off-by: Gustavo Pantuza Coelho Pinto <gustavopantuza@gmail.com>
This commit is contained in:
Gustavo Pantuza Coelho Pinto 2017-10-24 19:24:06 -02:00 committed by Joffrey F
parent 1b3acd0be8
commit 1833860614
1 changed files with 8 additions and 8 deletions

View File

@ -424,7 +424,7 @@ class TopLevelCommand(object):
Usage: exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]
Options:
-d Detached mode: Run command in the background.
-d, --detach Detached mode: Run command in the background.
--privileged Give extended privileges to the process.
-u, --user USER Run the command as this user.
-T Disable pseudo-tty allocation. By default `docker-compose exec`
@ -438,7 +438,7 @@ class TopLevelCommand(object):
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
index = int(options.get('--index'))
service = self.project.get_service(options['SERVICE'])
detach = options['-d']
detach = options.get('-d') or options.get('--detach')
if options['--env'] and docker.utils.version_lt(self.project.client.api_version, '1.25'):
raise UserError("Setting environment for exec is not supported in API < 1.25'")
@ -762,7 +762,7 @@ class TopLevelCommand(object):
SERVICE [COMMAND] [ARGS...]
Options:
-d Detached mode: Run container in the background, print
-d --detach Detached mode: Run container in the background, print
new container name.
--name NAME Assign a name to the container
--entrypoint CMD Override the entrypoint of the image.
@ -780,7 +780,7 @@ class TopLevelCommand(object):
-w, --workdir="" Working directory inside the container
"""
service = self.project.get_service(options['SERVICE'])
detach = options['-d']
detach = options.get('-d') or options.get('--detach')
if options['--publish'] and options['--service-ports']:
raise UserError(
@ -928,7 +928,7 @@ class TopLevelCommand(object):
Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...]
Options:
-d Detached mode: Run containers in the background,
-d, --detach Detached mode: Run containers in the background,
print new container names. Incompatible with
--abort-on-container-exit.
--no-color Produce monochrome output.
@ -963,7 +963,7 @@ class TopLevelCommand(object):
service_names = options['SERVICE']
timeout = timeout_from_opts(options)
remove_orphans = options['--remove-orphans']
detached = options.get('-d')
detached = options.get('-d') or options.get('--detach')
no_start = options.get('--no-start')
if detached and (cascade_stop or exit_value_from):
@ -975,7 +975,7 @@ class TopLevelCommand(object):
if ignore_orphans and remove_orphans:
raise UserError("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.")
opts = ['-d', '--abort-on-container-exit', '--exit-code-from']
opts = ['--detach', '--abort-on-container-exit', '--exit-code-from']
for excluded in [x for x in opts if options.get(x) and no_start]:
raise UserError('--no-start and {} cannot be combined.'.format(excluded))
@ -1245,7 +1245,7 @@ def run_one_off_container(container_options, project, service, options, project_
one_off=True,
**container_options)
if options['-d']:
if options.get('-d') or options.get('--detach'):
service.start_container(container)
print(container.name)
return