Sha256: 35eb45da5cbe7a4968d1486b6e66c2041bb4a6151f443eec31eedadb41d60681

Contents?: true

Size: 1.4 KB

Versions: 13

Compression:

Stored size: 1.4 KB

Contents

# -*- encoding : utf-8 -*-

module Phrase::Tool::Commands
  class Base
    def initialize(options, args=[])
      @options = options
      @args = args
    end
    
    def execute!
      raise "not implemented"
    end
    
    def require_auth_token!
      unless config.secret and config.secret.present?
        print_error "No auth token present. You need to initialize phrase first."
        exit_command
      end
    end
    
    def self.print_error(msg)
      $stderr.puts msg.red
    end
    
    def self.print_server_error(msg, location=nil)
      error_message = "#{msg}"
      error_message << " (#{location})" unless location.nil?
      print_error error_message
    end
    
    def self.print_message(msg)
      $stdout.puts msg
    end
        
    def self.exit_command
      exit()
    end
    
  protected
    def api_client
      Phrase::Api::Client.new(config.secret)
    end
    
    def config
      @config ||= get_config
    end
    
    def get_config
      config = Phrase::Tool::Config.new
      config.load
    end
    
    def options
      @options
    end
    
    def print_error(msg)
      self.class.print_error(msg)
    end
    
    def print_server_error(message, location=nil)
      self.class.print_server_error(message, location)
    end
    
    def print_message(msg)
      self.class.print_message(msg)
    end
    
    def exit_command
      self.class.exit_command
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
phrase-0.4.6 lib/phrase/tool/commands/base.rb
phrase-0.4.5 lib/phrase/tool/commands/base.rb
phrase-0.4.4 lib/phrase/tool/commands/base.rb
phrase-0.4.3 lib/phrase/tool/commands/base.rb
phrase-0.4.2 lib/phrase/tool/commands/base.rb
phrase-0.4.1 lib/phrase/tool/commands/base.rb
phrase-0.4.0 lib/phrase/tool/commands/base.rb
phrase-0.3.7 lib/phrase/tool/commands/base.rb
phrase-0.3.6 lib/phrase/tool/commands/base.rb
phrase-0.3.5 lib/phrase/tool/commands/base.rb
phrase-0.3.4 lib/phrase/tool/commands/base.rb
phrase-0.3.3 lib/phrase/tool/commands/base.rb
phrase-0.3.2 lib/phrase/tool/commands/base.rb