Sha256: 19f165aba9ec00b3387c3f0f1354a40499e00cf5c119369af90739ae9c18595a

Contents?: true

Size: 1003 Bytes

Versions: 4

Compression:

Stored size: 1003 Bytes

Contents

require 'psych'
require_relative 'command_base'
require_relative '../util'
require_relative '../parser'
require_relative '../yaml_ast_proxy'

class I18nFlow::CLI
  class CopyCommand < CommandBase
    def invoke!
      unless src_file && dst_file
        exit_with_message(1, 'usage: i18n_flow copy [--locale=LOCALE] SRC_FILE DST_FILE')
      end

      parser.parse!

      I18nFlow::YamlAstProxy.mark_as_todo(parser.root_proxy)

      if locale && first_key_node
        first_key_node.value = locale
      end

      File.write(dst_file, parser.root_proxy.to_yaml)
    end

    def src_file
      args[0]
    end

    def dst_file
      args[1]
    end

    def locale
      options['locale']
    end

    def first_key_node
      return @first_key_node if defined?(@first_key_node)
      @first_key_node = I18nFlow::YamlAstProxy.first_key_node_of(parser.root_proxy)
    end

  private

    def parser
      @parser ||= I18nFlow::Parser.new(File.read(src_file), file_path: src_file)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
i18n_flow-0.2.3 lib/i18n_flow/cli/copy_command.rb
i18n_flow-0.2.2 lib/i18n_flow/cli/copy_command.rb
i18n_flow-0.2.1 lib/i18n_flow/cli/copy_command.rb
i18n_flow-0.2.0 lib/i18n_flow/cli/copy_command.rb