Unify toplevel command handlers

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-02-27 11:24:40 -08:00
parent 7ce5766f6a
commit a7d1fada52

View File

@ -116,9 +116,9 @@ def perform_command(options, handler, command_options):
handler(command_options) handler(command_options)
return return
if options['COMMAND'] in ('config', 'bundle'): if options['COMMAND'] == 'config':
command = TopLevelCommand(None) command = TopLevelCommand(None, options=options)
handler(command, options, command_options) handler(command, command_options)
return return
project = project_from_options('.', options) project = project_from_options('.', options)
@ -279,7 +279,7 @@ class TopLevelCommand(object):
memory=options.get('--memory'), memory=options.get('--memory'),
build_args=build_args) build_args=build_args)
def bundle(self, config_options, options): def bundle(self, options):
""" """
Generate a Distributed Application Bundle (DAB) from the Compose file. Generate a Distributed Application Bundle (DAB) from the Compose file.
@ -298,8 +298,7 @@ class TopLevelCommand(object):
-o, --output PATH Path to write the bundle file to. -o, --output PATH Path to write the bundle file to.
Defaults to "<project name>.dab". Defaults to "<project name>.dab".
""" """
self.project = project_from_options('.', config_options) compose_config = get_config_from_options(self.project_dir, self.toplevel_options)
compose_config = get_config_from_options(self.project_dir, config_options)
output = options["--output"] output = options["--output"]
if not output: if not output:
@ -312,7 +311,7 @@ class TopLevelCommand(object):
log.info("Wrote bundle to {}".format(output)) log.info("Wrote bundle to {}".format(output))
def config(self, config_options, options): def config(self, options):
""" """
Validate and view the Compose file. Validate and view the Compose file.
@ -327,11 +326,12 @@ class TopLevelCommand(object):
""" """
compose_config = get_config_from_options(self.project_dir, config_options) compose_config = get_config_from_options(self.project_dir, self.toplevel_options)
image_digests = None image_digests = None
if options['--resolve-image-digests']: if options['--resolve-image-digests']:
self.project = project_from_options('.', config_options) self.project = project_from_options('.', self.toplevel_options)
with errors.handle_connection_errors(self.project.client):
image_digests = image_digests_for_project(self.project) image_digests = image_digests_for_project(self.project)
if options['--quiet']: if options['--quiet']:
@ -1144,7 +1144,6 @@ def timeout_from_opts(options):
def image_digests_for_project(project, allow_push=False): def image_digests_for_project(project, allow_push=False):
with errors.handle_connection_errors(project.client):
try: try:
return get_image_digests( return get_image_digests(
project, project,