Sha256: 6b8cb7f70d0452b1db45e27160716a6f4525dea9ea71d35bad21047036cfb225

Contents?: true

Size: 1.36 KB

Versions: 17

Compression:

Stored size: 1.36 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("\n")
  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

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fanforce-plugin-factory-2.0.0.rc10 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc9 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc8 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc7 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc6 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc5 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc3 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.1 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc2 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-2.0.0.rc1 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.0 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.0.rc6 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.0.rc5 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.0.rc4 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.0.rc3 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.0.rc2 lib/fanforce/plugin_factory/cli/lib/utils.rb
fanforce-plugin-factory-1.6.0.rc1 lib/fanforce/plugin_factory/cli/lib/utils.rb