Class: I18nFlow::CLI::CopyCommand

Inherits:
CommandBase show all
Defined in:
lib/i18n_flow/cli/copy_command.rb

Instance Method Summary collapse

Methods inherited from CommandBase

#color_enabled?, #exit_with_message, #initialize

Constructor Details

This class inherits a constructor from I18nFlow::CLI::CommandBase

Instance Method Details

#dst_fileObject



28
29
30
# File 'lib/i18n_flow/cli/copy_command.rb', line 28

def dst_file
  args[1]
end

#first_key_nodeObject



36
37
38
39
40
41
42
43
# File 'lib/i18n_flow/cli/copy_command.rb', line 36

def first_key_node
  return @first_key_node if defined?(@first_key_node)
  @first_key_node = parser.root_proxy
    .send(:indexed_object)
    .node
    .tap { |n| break unless n.is_a?(Psych::Nodes::Mapping) }
    &.tap { |n| break n.children.first }
end

#invoke!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/i18n_flow/cli/copy_command.rb', line 8

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

  parser.parse!

  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

#localeObject



32
33
34
# File 'lib/i18n_flow/cli/copy_command.rb', line 32

def locale
  options['locale']
end

#src_fileObject



24
25
26
# File 'lib/i18n_flow/cli/copy_command.rb', line 24

def src_file
  args[0]
end