From cbb9bff9243a8e2de24e74327caa21779a12e075 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 26 Mar 2018 14:25:31 -0700 Subject: [PATCH] Support -H=host notation for interactive run/execs Signed-off-by: Joffrey F --- compose/cli/main.py | 2 +- tests/acceptance/cli_test.py | 7 +++++++ tests/unit/cli/main_test.py | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index 9e49e2974..c05ba4988 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -1418,7 +1418,7 @@ def call_docker(args, dockeropts): if verify: tls_options.append('--tlsverify') if host: - tls_options.extend(['--host', host]) + tls_options.extend(['--host', host.lstrip('=')]) args = [executable_path] + tls_options + args log.debug(" ".join(map(pipes.quote, args))) diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index 14c96b24d..075705804 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -177,6 +177,13 @@ class CLITestCase(DockerClientTestCase): returncode=0 ) + def test_shorthand_host_opt_interactive(self): + self.dispatch( + ['-H={0}'.format(os.environ.get('DOCKER_HOST', 'unix://')), + 'run', 'another', 'ls'], + returncode=0 + ) + def test_host_not_reachable(self): result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1) assert "Couldn't connect to Docker daemon" in result.stderr diff --git a/tests/unit/cli/main_test.py b/tests/unit/cli/main_test.py index b46a3ee22..1a2dfbcf3 100644 --- a/tests/unit/cli/main_test.py +++ b/tests/unit/cli/main_test.py @@ -154,3 +154,11 @@ class TestCallDocker(object): assert fake_call.call_args[0][0] == [ 'docker', '--host', 'tcp://mydocker.net:2333', 'ps' ] + + def test_with_host_option_shorthand_equal(self): + with mock.patch('subprocess.call') as fake_call: + call_docker(['ps'], {'--host': '=tcp://mydocker.net:2333'}) + + assert fake_call.call_args[0][0] == [ + 'docker', '--host', 'tcp://mydocker.net:2333', 'ps' + ]