Sha256: 48bdd72f832a5d2c7bef8a35c0228b24afcf0cc268f440e58d79d9c97a92581d

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require_relative 'troo/troo'
require_relative 'troo/version'

module Troo
  class InvalidAccessToken < StandardError; end

  def self.config
    @config ||= OpenStruct.new(YAML.load_file(Dir.home + '/.trooconf'))
  rescue Errno::ENOENT
    warn 'No configuration file found...'
    src = File.dirname(__FILE__) + '/../configuration.yml.example'
    dst = Dir.home + '/.trooconf'
    FileUtils.cp(src, dst)
    warn "New configuration file created at '#{Dir.home}/.trooconf'"
    exit!
  end

  def self.logger
    @logger ||= Logger.new('logs/troo.log')
  end

  # Trello.logger = Logger.new("logs/trello.log")
  Trello.configure do |trello|
    trello.consumer_key       = config.key
    trello.consumer_secret    = config.secret
    trello.oauth_token        = config.oauth_token
    trello.oauth_token_secret = config.oauth_token_secret
  end

  class Launcher
    def initialize(argv, stdin = STDIN,
                         stdout = STDOUT,
                         stderr = STDERR,
                         kernel = Kernel)
      @argv = argv
      @stdin = stdin
      @stdout = stdout
      @stderr = stderr
      @kernel = kernel
    end

    def execute!
      $stdin, $stdout, $stderr = @stdin, @stdout, @stderr

      puts
      Troo::CLI::Main.start(@argv)
      puts

      @kernel.exit(0)
    rescue Troo::InvalidAccessToken
      @stderr.puts 'Your Trello access credentials have expired, ' \
                   ' please renew and try again.'
      @kernel.exit(1)
    rescue SocketError
      @stderr.puts 'Cannot continue, no network connection.'
      @kernel.exit(1)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.8 lib/troo.rb