Sha256: e3d2a084a4dccd446e2b25a31d834f084244636f86ca989b652401a51a70cfcd

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require 'fileutils'
require 'dockage/version'
require 'colorize'

module Dockage
  autoload :Settings, 'dockage/settings'
  autoload :Docker, 'dockage/docker'
  autoload :SSH, 'dockage/ssh'

  class DockageError          < StandardError; end
  class DockageConfigNotFound < DockageError; end
  class DockageConfigExists   < DockageError; end
  class ProvideError          < DockageError; end
  class InstallError          < DockageError; end
  class InvalidOptionError    < DockageError; end
  class SSHOptionsError       < DockageError; end

  class << self
    attr_accessor :debug_mode
    attr_accessor :verbose_mode
    attr_accessor :quiet_mode
    attr_accessor :force_mode

    def root
      @root ||= Dir.pwd
    end

    def config_path
      File.join(root, 'dockage.yml')
    end

    def settings
      @settings ||= Settings.load(config_path)
    end

    def create_example_config
      raise DockageConfigExists if File.exist? config_path
      FileUtils.cp(File.expand_path('../dockage/templates/dockage.yml', __FILE__), config_path)
      puts 'Created example config dockage.yml'
    end

    def which(executable)
      if File.file?(executable) && File.executable?(executable)
        executable
      elsif ENV['PATH']
        path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
          File.executable?(File.join(p, executable))
        end
        path && File.expand_path(executable, path)
      end
    end

    def debug(string)
      return unless string
      puts string.magenta if Dockage.debug_mode
    end

    def verbose(string)
      return unless string
      puts string.blue if Dockage.verbose_mode
    end

    def logger(string)
      return unless string
      puts "> #{string}" unless Dockage.quiet_mode
    end

    def error(string = 'unknown error')
      puts string.red unless Dockage.quiet_mode
      exit 1
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dockage-0.1.3 lib/dockage.rb
dockage-0.1.2 lib/dockage.rb
dockage-0.1.1 lib/dockage.rb
dockage-0.1.0 lib/dockage.rb