lib/dru/command.rb in dru-0.6.0 vs lib/dru/command.rb in dru-1.0.0
- old
+ new
@@ -4,20 +4,12 @@
module Dru
class Command
extend Forwardable
- class MissingContainerError < StandardError
- def initialize(msg = 'Missing container')
- super
- end
- end
-
attr_accessor :options
- def_delegators :command, :run
-
# Execute this command
#
# @api public
def execute(*)
raise(
@@ -34,80 +26,10 @@
def command(**options)
require 'tty-command'
TTY::Command.new({ printer: :quiet, uuid: false }.merge(options))
end
- # The cursor movement
- #
- # @see http://www.rubydoc.info/gems/tty-cursor
- #
- # @api public
- def cursor
- require 'tty-cursor'
- TTY::Cursor
- end
-
- # Open a file or text in the user's preferred editor
- #
- # @see http://www.rubydoc.info/gems/tty-editor
- #
- # @api public
- def editor
- require 'tty-editor'
- TTY::Editor
- end
-
- # File manipulation utility methods
- #
- # @see http://www.rubydoc.info/gems/tty-file
- #
- # @api public
- def generator
- require 'tty-file'
- TTY::File
- end
-
- # Terminal output paging
- #
- # @see http://www.rubydoc.info/gems/tty-pager
- #
- # @api public
- def pager(**options)
- require 'tty-pager'
- TTY::Pager.new(options)
- end
-
- # Terminal platform and OS properties
- #
- # @see http://www.rubydoc.info/gems/tty-pager
- #
- # @api public
- def platform
- require 'tty-platform'
- TTY::Platform.new
- end
-
- # The interactive prompt
- #
- # @see http://www.rubydoc.info/gems/tty-prompt
- #
- # @api public
- def prompt(**options)
- require 'tty-prompt'
- TTY::Prompt.new(options)
- end
-
- # Get terminal screen properties
- #
- # @see http://www.rubydoc.info/gems/tty-screen
- #
- # @api public
- def screen
- require 'tty-screen'
- TTY::Screen
- end
-
# The unix which utility
#
# @see http://www.rubydoc.info/gems/tty-which
#
# @api public
@@ -140,40 +62,53 @@
def default_docker_compose
File.join(project_configuration_path, 'docker-compose.yml')
end
- def environment_docker_compose
- return unless environment
-
- File.join(project_configuration_path, "docker-compose.#{environment}.yml")
+ def override_docker_compose
+ override = environment || 'override'
+ docker_compose_file = File.join(project_configuration_path, "docker-compose.#{override}.yml")
+ return unless File.exist?(docker_compose_file)
+ docker_compose_file
end
def docker_compose_paths
- docker_compose_default_path + docker_compose_environment_path
+ docker_compose_default_path + docker_compose_override_path
end
- def run_docker_compose_command(*args, **options)
- if options[:tty]
- system(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args)
- else
- command(options).run(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args)
+ def run(*command, **options)
+ command(options).run!(*command, { in: '/dev/tty', err: '/dev/tty' }.merge(options)).tap do |result|
+ raise Dru::CLI::Error, result.err unless result.success?
end
end
- def container_name_to_id(container_name = 'app')
- run_docker_compose_command('ps', '-q', container_name, printer: :null).first
+ def run_docker_compose_command(*command, **options)
+ run(DOCKER_COMPOSE_COMMAND, '-p', docker_compose_project_name, *docker_compose_paths, *command, **options)
end
+ def run_docker_command(*command, **options)
+ run(DOCKER_COMMAND, *command, **options)
+ end
+
+ def container_name_to_id(container_name)
+ run_docker_compose_command('ps', '-q', container_name, only_output_on_error: true).out.strip
+ end
+
+ def docker_compose_project_name
+ return project_name unless environment
+
+ "#{project_name}_#{environment}"
+ end
+
private
def docker_compose_default_path
['-f', default_docker_compose]
end
- def docker_compose_environment_path
- return [] unless environment_docker_compose
+ def docker_compose_override_path
+ return [] unless override_docker_compose
- ['-f', environment_docker_compose]
+ ['-f', override_docker_compose]
end
end
end