Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit e0ae53c

Browse files
committed
feat(run): Add tty option
1 parent 39a6506 commit e0ae53c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

docker/manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
6060
if exc_value:
6161
raise exc_value
6262

63-
def run(self, command, working_directory='', stdin='', login=True):
63+
def run(self, command, working_directory='', stdin='', login=True, tty=True):
6464
"""
6565
Runs the command with docker exec in the given working directory.
6666
@@ -74,6 +74,8 @@ def run(self, command, working_directory='', stdin='', login=True):
7474
:type stdin: str
7575
:param login: Will add --login on the bash call.
7676
:type login: boolean
77+
:param tty: Will add -t on the bash call.
78+
:type tty: boolean
7779
:return: A ProcessResult object containing information on the result of the command.
7880
:rtype: ProcessResult
7981
"""
@@ -89,10 +91,11 @@ def run(self, command, working_directory='', stdin='', login=True):
8991
])
9092

9193
result = execute(
92-
'docker exec -i {container} bash {login} -c \'{command}\''.format(
94+
'docker exec -i{tty} {container} bash{login} -c \'{command}\''.format(
9395
envs=env_string,
9496
container=self.container_name,
95-
login='--login' if login else '',
97+
login=' --login' if login else '',
98+
tty=' -t' if tty else '',
9699
command=command_string.format(
97100
working_directory=working_directory,
98101
command=command,

tests/test_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_quotation_mark_handling(self, mock_run):
7070
docker.run('echo "hi there"')
7171
docker.run("echo 'hi there'")
7272
expected = (
73-
'docker exec -i {} bash --login -c \'cd ~/ && echo "hi there"\''.format(
73+
'docker exec -i -t {} bash --login -c \'cd ~/ && echo "hi there"\''.format(
7474
docker.container_name
7575
),
7676
''
@@ -84,7 +84,7 @@ def test_env_variables(self, mock_run):
8484
docker = Docker(env_variables={'CI': 1, 'FRIGG': 1})
8585
docker.run('ls')
8686
mock_run.assert_called_once_with(
87-
'docker exec -i {} bash --login -c \'cd ~/ && CI=1 FRIGG=1 ls\''.format(
87+
'docker exec -i -t {} bash --login -c \'cd ~/ && CI=1 FRIGG=1 ls\''.format(
8888
docker.container_name
8989
),
9090
''
@@ -96,7 +96,7 @@ def test_no_login(self, mock_run):
9696
docker = Docker()
9797
docker.run('ls', login=False)
9898
mock_run.assert_called_once_with(
99-
'docker exec -i {} bash -c \'cd ~/ && ls\''.format(docker.container_name),
99+
'docker exec -i -t {} bash -c \'cd ~/ && ls\''.format(docker.container_name),
100100
''
101101
)
102102

0 commit comments

Comments
 (0)