Sha256: 3b24e1a5c112abd5a50ce5c016e12e084c889d24a164d1db27dd789217cf3940

Contents?: true

Size: 1.52 KB

Versions: 17

Compression:

Stored size: 1.52 KB

Contents

require 'pty'
require 'fanforce/cli'

module Fanforce::PluginFactory::CLI::Utils
  extend self
  def self.included(base) base.extend(self) end

  include Fanforce::CLI::Utils

  @@config = nil

  def console_command(command, print_now=false)
    output = []
    PTY.spawn(command) do |stdin, stdout, pid|
      stdin.each { |line| output << line; print line if print_now }
    end
    output.join('')
  end

  def silence_warnings
    require 'stringio'
    old_stderr = $stderr
    $stderr = StringIO.new
    yield
  ensure
    $stderr = old_stderr
  end

  def config_filepath
    if Fanforce::CLI::TYPE == :directory_of_plugins
      "#{Fanforce::CLI::DIR}/.fanforce-plugin-factory"
    elsif Fanforce::CLI::TYPE == :single_plugin
      "#{Fanforce::CLI::DIR}/../.fanforce-plugin-factory"
    end
  end

  def config_relativepath
    if Fanforce::CLI::TYPE == :directory_of_plugins
      '.fanforce-plugin-factory'
    elsif Fanforce::CLI::TYPE == :single_plugin
      '../.fanforce-plugin-factory'
    end
  end

  def config
    return @@config if @@config
    require 'yaml'
    error "The required config file was not found: #{config_relativepath}" if !File.exists?(config_filepath)
    @@config = format_config(YAML.load_file(config_filepath))
  end

  def format_config(hash)
    hash.values.select{|v| v.is_a? Hash}.each{|h| format_config(h)}
    hash.symbolize_keys!
  end

  def env(environment)
    case environment.to_sym
      when :development then :dev
      when :staging     then :stg
      when :production  then :prd
    end
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fanforce-plugin-factory-2.0.0.rc29 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc28 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc27 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc26 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc25 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc24 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc23 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc22 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc21 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc19 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc18 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc17 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc16 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc15 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc13 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc12 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc11 lib/fanforce/plugin_factory/cli/lib/utils.rb