require 'pty' require 'fanforce/cli' module Fanforce::AppFactory::CLI::Utils extend self def self.included(base) base.extend(self) end include Fanforce::CLI::Utils @@config = nil def console_command(command, print_now=true) output = [] PTY.spawn(command) do |stdin, stdout, pid| stdin.each { |line| output << line; print line if print_now } end output.join("\n") end def config return @@config if @@config require 'yaml' if Fanforce::CLI::TYPE == :directory_of_apps config_path = "#{Fanforce::CLI::DIR}/.fanforce-app-factory" config_filename = '.fanforce-app-factory' elsif Fanforce::CLI::TYPE == :single_app config_path = "#{Fanforce::CLI::DIR}/../.fanforce-app-factory" config_filename = '../.fanforce-app-factory' end error "The required config file was not found: #{config_filename}" if !File.exists?(config_path) @@config = format_config(YAML.load_file(config_path)) end def format_config(hash) hash.values.select{|v| v.is_a? Hash}.each{|h| format_config(h)} hash.symbolize_keys! end end