Skip to content

Commit

Permalink
Remove the deprecated tree-rename-key command
Browse files Browse the repository at this point in the history
Use `tree-mv` instead.
  • Loading branch information
glebm committed Aug 3, 2018
1 parent 5f147ad commit c1d1312
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 54 deletions.
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ en:
tree_filter: filter tree by key pattern
tree_merge: merge trees
tree_mv_key: rename/merge/remove the keys matching the given pattern
tree_rename_key: rename tree node
tree_set_value: set values of keys, optionally match a pattern
tree_subtract: tree A minus the keys in tree B
tree_translate: Google Translate a tree to root locales
Expand Down
1 change: 0 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ru:
tree_filter: фильтровать дерево по ключу
tree_merge: объединенить деревья
tree_mv_key: переименованить / объединить / удалить ключи соответствующие заданному шаблону
tree_rename_key: переименовать узел дерева
tree_set_value: заменить значения ключей
tree_subtract: дерево A минус ключи в дереве B
tree_translate: Перевести дерево при помощи Google Translate на язык корневых узлов
Expand Down
18 changes: 0 additions & 18 deletions lib/i18n/tasks/command/commands/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ def tree_filter(opts = {})
print_forest forest, opts
end

cmd :tree_rename_key,
pos: 'KEY_PATTERN NAME [tree (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_rename_key'),
args: [['-k', '--key KEY_PATTERN', t('i18n_tasks.cmd.args.desc.key_pattern_to_rename')],
['-n', '--name NAME', t('i18n_tasks.cmd.args.desc.new_key_name')],
:data_format]

def tree_rename_key(opt = {})
warn_deprecated 'Use tree-mv instead.'
key = arg_or_pos! :key, opt
name = arg_or_pos! :name, opt
forest = forest_pos_or_stdin! opt
fail CommandError, 'pass full key to rename (-k, --key)' if key.blank?
fail CommandError, 'pass new name (-n, --name)' if name.blank?
forest.rename_each_key!(key, name)
print_forest forest, opt
end

arg :all_locales,
'-a',
'--all-locales',
Expand Down
14 changes: 0 additions & 14 deletions lib/i18n/tasks/data/tree/siblings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ def rename_key(key, new_key)
self
end

def rename_each_key!(full_key_pattern, new_key_tpl)
pattern_re = I18n::Tasks::KeyPatternMatching.compile_key_pattern(full_key_pattern)
nodes do |node|
next if node.full_key(root: true) !~ pattern_re
new_key = new_key_tpl.gsub('%{key}', node.key)
if node.parent == parent
rename_key(node.key, new_key)
else
node.parent.children.rename_key(node.key, new_key)
end
end
self
end

# @param from_pattern [Regexp]
# @param to_pattern [Regexp]
# @param root [Boolean]
Expand Down
20 changes: 0 additions & 20 deletions spec/commands/tree_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,6 @@
end
end

context 'tree-rename-key' do
def forest
{ 'a' => { 'b' => { 'a' => '1' } } }
end

def rename_key(from, to)
JSON.parse run_cmd('tree-rename-key', '-fjson', '-k', from, '-n', to, forest.to_json)
end

it 'renames root node' do
expect(rename_key('a', 'x')).to eq(forest.tap { |f| f['x'] = f.delete('a') })
end
it 'renames node' do
expect(rename_key('a.b', 'x')).to eq(forest.tap { |f| f['a']['x'] = f['a'].delete('b') })
end
it 'renames leaf' do
expect(rename_key('a.b.a', 'x')).to eq(forest.tap { |f| f['a']['b']['x'] = f['a']['b'].delete('a') })
end
end

context 'tree-mv' do
def tree_mv(from, to, forest, all_locales: false)
output = run_cmd('tree-mv', *(['-a'] if all_locales), '-fyaml', from, to, forest.to_yaml.sub(/\A---\n/, ''))
Expand Down

0 comments on commit c1d1312

Please sign in to comment.