Sha256: 8bea773ff8768ac5e13891596bdd0f84f52f92172e22ce9a6855ac2dc83bd0f4

Contents?: true

Size: 1.54 KB

Versions: 8

Compression:

Stored size: 1.54 KB

Contents

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

class Phrase::Tool::Commands::Init < Phrase::Tool::Commands::Base
  def initialize(options, args)
    super(options, args)
  end
  
  def execute!
    secret = get_option(:secret)
    if secret.present?
      config.secret = secret
      print_message "Wrote secret to config file .phrase"
      config.default_locale = get_option(:default_locale)
      create_locale(config.default_locale)
      make_locale_default(config.default_locale)
      config.format = get_option(:format)
      config.target_directory = get_option(:target_directory)
      config.domain = get_option(:domain)
      config.locale_directory = get_option(:locale_directory)
      config.locale_filename = get_option(:locale_filename)
    else
      print_auth_token_error
      exit_command
    end
  end
  
private
  def create_locale(name)
    begin
      api_client.create_locale(name)
      print_message "Created locale \"#{name}\"".green
    rescue Exception => e
      print_message "Notice: Locale \"#{name}\" could not be created (maybe it already exists)".light_red
    end
  end
  
  def make_locale_default(name)
    begin
      api_client.make_locale_default(name)
      print_message "Locale \"#{name}\" is now the default locale".green
    rescue Exception => e
      print_message "Notice: Locale \"#{name}\" could not be made the default locale".light_red
      print_server_error(e.message)
    end
  end
  
  def print_auth_token_error
    print_error "No auth token was given"
    print_error "Please provide the --secret=YOUR_SECRET parameter."
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
phrase-0.4.14 lib/phrase/tool/commands/init.rb
phrase-0.4.13 lib/phrase/tool/commands/init.rb
phrase-0.4.12 lib/phrase/tool/commands/init.rb
phrase-0.4.11 lib/phrase/tool/commands/init.rb
phrase-0.4.10 lib/phrase/tool/commands/init.rb
phrase-0.4.9 lib/phrase/tool/commands/init.rb
phrase-0.4.8 lib/phrase/tool/commands/init.rb
phrase-0.4.7 lib/phrase/tool/commands/init.rb