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