Packages
A typed Elixir wrapper for the Docker CLI with struct-based commands and pipeline composition
Current section
Files
Jump to
Current section
Files
lib/docker/commands/compose/stop.ex
defmodule Docker.Commands.Compose.Stop do
@moduledoc """
Implements the `Docker.Command` behaviour for `docker compose stop`.
"""
@behaviour Docker.Command
import Docker.Command, only: [add_opt: 3]
require Docker.Commands.Compose.Common
alias Docker.Commands.Compose.Common
defstruct Common.compose_fields(services: [], timeout: nil)
@type t :: %__MODULE__{}
def new, do: %__MODULE__{}
def file(%__MODULE__{} = cmd, f), do: %{cmd | files: cmd.files ++ [f]}
def project_name(%__MODULE__{} = cmd, n), do: %{cmd | project_name: n}
def service(%__MODULE__{} = cmd, s), do: %{cmd | services: cmd.services ++ [s]}
def timeout(%__MODULE__{} = cmd, t), do: %{cmd | timeout: t}
@impl true
def args(%__MODULE__{} = cmd) do
Common.compose_prefix(cmd)
|> Kernel.++(["stop"])
|> add_opt(cmd.timeout && to_string(cmd.timeout), "-t")
|> Kernel.++(cmd.services)
end
@impl true
def parse_output(stdout, 0), do: {:ok, stdout}
def parse_output(stdout, exit_code), do: {:error, {stdout, exit_code}}
end