lib/i18n/tasks/command/commands/tree.rb in i18n-tasks-0.9.7 vs lib/i18n/tasks/command/commands/tree.rb in i18n-tasks-0.9.8
- old
+ new
@@ -2,10 +2,11 @@
module I18n::Tasks
module Command
module Commands
module Tree
include Command::Collection
+ include I18n::Tasks::KeyPatternMatching
cmd :tree_translate,
pos: '[tree (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_translate'),
args: [:locale_to_translate_from, arg(:data_format).from(1)]
@@ -45,15 +46,29 @@
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
+
+ cmd :tree_mv,
+ pos: 'FROM_KEY_PATTERN TO_KEY_PATTERN [tree (or stdin)]',
+ desc: t('i18n_tasks.cmd.desc.tree_mv_key'),
+ args: [:data_format]
+ def tree_mv(opt = {})
+ fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
+ from_pattern = opt[:arguments].shift
+ to_pattern = opt[:arguments].shift
+ forest = forest_pos_or_stdin!(opt)
+ forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: false)
print_forest forest, opt
end
cmd :tree_subtract,
pos: '[[tree] [tree] ... (or stdin)]',