Sha256: 91587412398e070815b8a6778c2d61db3e4ad2346bcc9e1683b923a8ea2c6d03

Contents?: true

Size: 810 Bytes

Versions: 3

Compression:

Stored size: 810 Bytes

Contents

# frozen_string_literal: true

require_relative '../command'

module Dru
  module Commands
    class Up < Dru::Command
      DOCKER_ATTACH_COMMAND = 'docker attach --detach-keys="ctrl-d"'.freeze

      def initialize(options:)
        @options = options
      end

      def execute(input: $stdin, output: $stdout)
        start_docker_compose
        return if options[:detach]

        stop_docker_compose if attach_to_default_container
      end

      private

      def start_docker_compose
        run_docker_compose_command('up', '-d')
      end

      def stop_docker_compose
        run_docker_compose_command('down')
      end

      def attach_to_default_container(container_name = 'app')
        system "#{DOCKER_ATTACH_COMMAND} #{container_name_to_id(container_name)}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dru-0.5.0 lib/dru/commands/up.rb
dru-0.4.0 lib/dru/commands/up.rb
dru-0.3.1 lib/dru/commands/up.rb