lib/i18n/tasks/command/commands/tree.rb in i18n-tasks-0.7.13 vs lib/i18n/tasks/command/commands/tree.rb in i18n-tasks-0.8.0
- old
+ new
@@ -3,96 +3,92 @@
module Commands
module Tree
include Command::Collection
cmd :tree_translate,
- args: '[tree]',
+ pos: '[tree (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_translate'),
- opt: cmd_opts(:locale_to_translate_from) << cmd_opt(:data_format).except(:short)
+ args: [:locale_to_translate_from, arg(:data_format).from(1)]
def tree_translate(opts = {})
- forest = opt_forest_arg_or_stdin!(opts)
- from = opts[:from]
- translated = i18n.google_translate_forest(forest, from)
- print_forest translated, opts
+ forest = forest_pos_or_stdin!(opts)
+ print_forest i18n.google_translate_forest(forest, opts[:from]), opts
end
cmd :tree_merge,
- args: '[tree ...]',
+ pos: '[[tree] [tree] ... (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_merge'),
- opt: cmd_opts(:data_format, :nostdin)
+ args: [:data_format, :nostdin]
def tree_merge(opts = {})
- print_forest opt_forests_merged_stdin_args!(opts), opts
+ print_forest merge_forests_stdin_and_pos!(opts), opts
end
cmd :tree_filter,
- args: '[pattern] [tree]',
+ pos: '[pattern] [tree (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_filter'),
- opt: cmd_opts(:data_format, :pattern)
+ args: [:data_format, :pattern]
- def tree_filter(opt = {})
- pattern = opt_or_arg! :pattern, opt
- forest = opt_forest_arg_or_stdin!(opt)
+ def tree_filter(opts = {})
+ pattern = arg_or_pos! :pattern, opts
+ forest = forest_pos_or_stdin! opts
unless pattern.blank?
pattern_re = i18n.compile_key_pattern(pattern)
forest = forest.select_keys { |full_key, _node| full_key =~ pattern_re }
end
- print_forest forest, opt
+ print_forest forest, opts
end
cmd :tree_rename_key,
- args: '<key> <name> [tree]',
+ pos: 'KEY_PATTERN NAME [tree (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_rename_key'),
- opt: [cmd_opt(:pattern).merge(short: :k, long: :key=,
- desc: t('i18n_tasks.cmd.args.desc.key_pattern_to_rename')),
- cmd_opt(:pattern).merge(short: :n, long: :name=,
- desc: t('i18n_tasks.cmd.args.desc.new_key_name')),
- *cmd_opts(:data_format)]
+ 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 = {})
- key = opt_or_arg! :key, opt
- name = opt_or_arg! :name, opt
- forest = opt_forest_arg_or_stdin! opt
+ key = arg_or_pos! :key, opt
+ name = arg_or_pos! :name, opt
+ forest = forest_pos_or_stdin! opt
raise CommandError.new('pass full key to rename (-k, --key)') if key.blank?
raise CommandError.new('pass new name (-n, --name)') if name.blank?
forest.rename_each_key!(key, name)
print_forest forest, opt
end
cmd :tree_subtract,
- args: '[tree A] [tree B ...]',
+ pos: '[[tree] [tree] ... (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_subtract'),
- opt: cmd_opts(:data_format, :nostdin)
+ args: [:data_format, :nostdin]
def tree_subtract(opt = {})
- forests = opt_forests_stdin_args! opt, 2
+ forests = forests_stdin_and_pos! opt, 2
forest = forests.reduce(:subtract_by_key) || empty_forest
print_forest forest, opt
end
cmd :tree_set_value,
- args: '[value] [tree]',
+ pos: '[VALUE] [tree (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_set_value'),
- opt: cmd_opts(:value, :data_format, :nostdin, :pattern)
+ args: [:value, :data_format, :nostdin, :pattern]
def tree_set_value(opt = {})
- value = opt_or_arg! :value, opt
- forest = opt_forest_arg_or_stdin!(opt)
+ value = arg_or_pos! :value, opt
+ forest = forest_pos_or_stdin!(opt)
key_pattern = opt[:pattern]
raise CommandError.new('pass value (-v, --value)') if value.blank?
forest.set_each_value!(value, key_pattern)
print_forest forest, opt
end
cmd :tree_convert,
- args: '<tree>',
+ pos: '[tree (or stdin)]',
desc: t('i18n_tasks.cmd.desc.tree_convert'),
- opt: [cmd_opt(:data_format).merge(short: :f, long: :from=),
- cmd_opt(:out_format).merge(short: :t, long: :to=)]
+ args: [arg(:data_format).dup.tap { |a| a[0..1] = ['-f', '--from FORMAT'] },
+ arg(:out_format).dup.tap { |a| a[0..1] = ['-t', '--to FORMAT'] }]
def tree_convert(opt = {})
- forest = opt_forest_arg_or_stdin! opt.merge(format: opt[:from])
+ forest = forest_pos_or_stdin! opt.merge(format: opt[:from])
print_forest forest, opt.merge(format: opt[:to])
end
end
end
end