From 1da43016507dafb1823d8732d9a99be7abf9739c Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Mon, 1 Mar 2021 19:23:03 -0300 Subject: [PATCH] Advertise `docker compose` for non linux users This adds messages on: - Root command (only `docker-compose`) - Command not found - `help` command Signed-off-by: Ulysses Souza --- compose/cli/main.py | 12 ++++++++++++ compose/const.py | 1 + tox.ini | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index 494e85620..33c2ba8c9 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -23,6 +23,7 @@ from ..config import resolve_build_args from ..config.environment import Environment from ..config.serialize import serialize_config from ..config.types import VolumeSpec +from ..const import IS_LINUX_PLATFORM from ..const import IS_WINDOWS_PLATFORM from ..errors import StreamParseError from ..metrics.decorator import metrics @@ -78,6 +79,8 @@ def main(): # noqa: C901 try: command_func = dispatch() command_func() + if not IS_LINUX_PLATFORM and command == 'help': + print("\nDocker Compose is now in the Docker CLI, try `docker compose` help") except (KeyboardInterrupt, signals.ShutdownException): exit_with_metrics(command, "Aborting.", status=Status.FAILURE) except (UserError, NoSuchService, ConfigurationError, @@ -98,6 +101,8 @@ def main(): # noqa: C901 e.service.name), status=Status.FAILURE) except NoSuchCommand as e: commands = "\n".join(parse_doc_section("commands:", getdoc(e.supercommand))) + if not IS_LINUX_PLATFORM: + commands += "\n\nDocker Compose is now in the Docker CLI, try `docker compose`" exit_with_metrics(e.command, "No such command: {}\n\n{}".format(e.command, commands)) except (errors.ConnectionError, StreamParseError): exit_with_metrics(command, status=Status.FAILURE) @@ -116,6 +121,10 @@ def main(): # noqa: C901 code = 0 if isinstance(e.code, int): code = e.code + + if not IS_LINUX_PLATFORM and not command: + msg += "\n\nDocker Compose is now in the Docker CLI, try `docker compose`" + exit_with_metrics(command, log_msg=msg, status=status, exit_code=code) @@ -1123,6 +1132,9 @@ class TopLevelCommand: attach_dependencies = options.get('--attach-dependencies') keep_prefix = not options.get('--no-log-prefix') + if not IS_LINUX_PLATFORM: + print('Docker Compose is now in the Docker CLI, try `docker compose up`\n') + if detached and (cascade_stop or exit_value_from or attach_dependencies): raise UserError( "-d cannot be combined with --abort-on-container-exit or --attach-dependencies.") diff --git a/compose/const.py b/compose/const.py index 043429802..90cd38e82 100644 --- a/compose/const.py +++ b/compose/const.py @@ -5,6 +5,7 @@ from .version import ComposeVersion DEFAULT_TIMEOUT = 10 HTTP_TIMEOUT = 60 IS_WINDOWS_PLATFORM = (sys.platform == "win32") +IS_LINUX_PLATFORM = (sys.platform == "linux") LABEL_CONTAINER_NUMBER = 'com.docker.compose.container-number' LABEL_ONE_OFF = 'com.docker.compose.oneoff' LABEL_PROJECT = 'com.docker.compose.project' diff --git a/tox.ini b/tox.ini index 80b6e256d..12530d191 100644 --- a/tox.ini +++ b/tox.ini @@ -50,7 +50,7 @@ directory = coverage-html [flake8] max-line-length = 105 # Set this high for now -max-complexity = 11 +max-complexity = 12 exclude = compose/packages [pytest]