Pārlūkot izejas kodu

Friendlier connection error for docker-osx users

Aanand Prasad 12 gadi atpakaļ
vecāks
revīzija
5126649de4
2 mainītis faili ar 14 papildinājumiem un 2 dzēšanām
  1. 5 2
      fig/cli/command.py
  2. 9 0
      fig/cli/utils.py

+ 5 - 2
fig/cli/command.py

@@ -11,7 +11,7 @@ import yaml
 from ..project import Project
 from .docopt_command import DocoptCommand
 from .formatter import Formatter
-from .utils import cached_property, docker_url
+from .utils import cached_property, docker_url, call_silently
 from .errors import UserError
 
 log = logging.getLogger(__name__)
@@ -23,7 +23,10 @@ class Command(DocoptCommand):
         try:
             super(Command, self).dispatch(*args, **kwargs)
         except ConnectionError:
-            raise UserError("""
+            if call_silently(['which', 'docker-osx']) == 0:
+                raise UserError("Couldn't connect to Docker daemon - you might need to run `docker-osx shell`.")
+            else:
+                raise UserError("""
 Couldn't connect to Docker daemon at %s - is it running?
 
 If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

+ 9 - 0
fig/cli/utils.py

@@ -4,6 +4,7 @@ from __future__ import division
 import datetime
 import os
 import socket
+import subprocess
 from .errors import UserError
 
 
@@ -108,3 +109,11 @@ def split_buffer(reader, separator):
 
     if len(buffered) > 0:
         yield buffered
+
+
+def call_silently(*args, **kwargs):
+    """
+    Like subprocess.call(), but redirects stdout and stderr to /dev/null.
+    """
+    with open(os.devnull, 'w') as shutup:
+        return subprocess.call(*args, stdout=shutup, stderr=shutup, **kwargs)