i18n-tasks 0.7.13 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +11 -0
  3. data/Gemfile +5 -3
  4. data/README.md +27 -126
  5. data/bin/i18n-tasks +2 -45
  6. data/config/locales/en.yml +11 -14
  7. data/config/locales/ru.yml +0 -3
  8. data/i18n-tasks.gemspec +0 -1
  9. data/lib/i18n/tasks.rb +14 -2
  10. data/lib/i18n/tasks/cli.rb +195 -0
  11. data/lib/i18n/tasks/command/collection.rb +2 -2
  12. data/lib/i18n/tasks/command/commander.rb +4 -24
  13. data/lib/i18n/tasks/command/commands/data.rb +17 -19
  14. data/lib/i18n/tasks/command/commands/eq_base.rb +2 -2
  15. data/lib/i18n/tasks/command/commands/health.rb +2 -2
  16. data/lib/i18n/tasks/command/commands/meta.rb +2 -2
  17. data/lib/i18n/tasks/command/commands/missing.rb +22 -15
  18. data/lib/i18n/tasks/command/commands/tree.rb +31 -35
  19. data/lib/i18n/tasks/command/commands/usages.rb +10 -11
  20. data/lib/i18n/tasks/command/commands/xlsx.rb +3 -3
  21. data/lib/i18n/tasks/command/dsl.rb +22 -7
  22. data/lib/i18n/tasks/command/option_parsers/enum.rb +53 -0
  23. data/lib/i18n/tasks/command/option_parsers/locale.rb +48 -0
  24. data/lib/i18n/tasks/command/options/common.rb +21 -31
  25. data/lib/i18n/tasks/command/options/data.rb +91 -0
  26. data/lib/i18n/tasks/command/options/locales.rb +22 -42
  27. data/lib/i18n/tasks/data/file_system_base.rb +2 -2
  28. data/lib/i18n/tasks/data/tree/node.rb +3 -3
  29. data/lib/i18n/tasks/data/tree/nodes.rb +3 -2
  30. data/lib/i18n/tasks/data/tree/siblings.rb +0 -1
  31. data/lib/i18n/tasks/logging.rb +9 -5
  32. data/lib/i18n/tasks/scanners/base_scanner.rb +6 -7
  33. data/lib/i18n/tasks/scanners/relative_keys.rb +1 -1
  34. data/lib/i18n/tasks/version.rb +1 -1
  35. data/spec/commands/data_commands_spec.rb +4 -4
  36. data/spec/commands/tree_commands_spec.rb +5 -5
  37. data/spec/google_translate_spec.rb +2 -3
  38. data/spec/i18n_spec.rb +0 -1
  39. data/spec/i18n_tasks_spec.rb +44 -23
  40. data/spec/readme_spec.rb +1 -1
  41. data/spec/support/test_codebase.rb +21 -10
  42. data/templates/config/i18n-tasks.yml +51 -39
  43. data/templates/rspec/i18n_spec.rb +0 -1
  44. metadata +6 -23
  45. data/lib/i18n/tasks/command/dsl/cmd.rb +0 -19
  46. data/lib/i18n/tasks/command/dsl/cmd_opt.rb +0 -19
  47. data/lib/i18n/tasks/command/dsl/enum_opt.rb +0 -45
  48. data/lib/i18n/tasks/command/options/enum_opt.rb +0 -50
  49. data/lib/i18n/tasks/command/options/list_opt.rb +0 -11
  50. data/lib/i18n/tasks/command/options/trees.rb +0 -81
  51. data/lib/i18n/tasks/slop_command.rb +0 -41
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'i18n/tasks'
3
2
 
4
3
  describe 'I18n' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.13
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: slop
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.5'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.5'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: i18n
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -219,6 +205,7 @@ files:
219
205
  - i18n-tasks.gemspec
220
206
  - lib/i18n/tasks.rb
221
207
  - lib/i18n/tasks/base_task.rb
208
+ - lib/i18n/tasks/cli.rb
222
209
  - lib/i18n/tasks/command/collection.rb
223
210
  - lib/i18n/tasks/command/commander.rb
224
211
  - lib/i18n/tasks/command/commands/data.rb
@@ -230,14 +217,11 @@ files:
230
217
  - lib/i18n/tasks/command/commands/usages.rb
231
218
  - lib/i18n/tasks/command/commands/xlsx.rb
232
219
  - lib/i18n/tasks/command/dsl.rb
233
- - lib/i18n/tasks/command/dsl/cmd.rb
234
- - lib/i18n/tasks/command/dsl/cmd_opt.rb
235
- - lib/i18n/tasks/command/dsl/enum_opt.rb
220
+ - lib/i18n/tasks/command/option_parsers/enum.rb
221
+ - lib/i18n/tasks/command/option_parsers/locale.rb
236
222
  - lib/i18n/tasks/command/options/common.rb
237
- - lib/i18n/tasks/command/options/enum_opt.rb
238
- - lib/i18n/tasks/command/options/list_opt.rb
223
+ - lib/i18n/tasks/command/options/data.rb
239
224
  - lib/i18n/tasks/command/options/locales.rb
240
- - lib/i18n/tasks/command/options/trees.rb
241
225
  - lib/i18n/tasks/command_error.rb
242
226
  - lib/i18n/tasks/commands.rb
243
227
  - lib/i18n/tasks/configuration.rb
@@ -270,7 +254,6 @@ files:
270
254
  - lib/i18n/tasks/scanners/pattern_scanner.rb
271
255
  - lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb
272
256
  - lib/i18n/tasks/scanners/relative_keys.rb
273
- - lib/i18n/tasks/slop_command.rb
274
257
  - lib/i18n/tasks/split_key.rb
275
258
  - lib/i18n/tasks/stats.rb
276
259
  - lib/i18n/tasks/string_interpolation.rb
@@ -1,19 +0,0 @@
1
- module I18n::Tasks
2
- module Command
3
- module DSL
4
- module Cmd
5
- def cmd(name, args = nil)
6
- if args
7
- dsl(:cmds)[name] = args
8
- else
9
- dsl(:cmds)[name]
10
- end
11
- end
12
-
13
- def cmds
14
- dsl(:cmds)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module I18n::Tasks
2
- module Command
3
- module DSL
4
- module CmdOpt
5
- def cmd_opts(*args)
6
- dsl(:cmd_opts).values_at(*args)
7
- end
8
-
9
- def cmd_opt(arg, opts = nil)
10
- if opts
11
- dsl(:cmd_opts)[arg] = opts
12
- else
13
- dsl(:cmd_opts)[arg]
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,45 +0,0 @@
1
- module I18n::Tasks
2
- module Command
3
- module DSL
4
- module EnumOpt
5
- def enum_opt(name, list = nil)
6
- if list
7
- dsl(:enum_valid)[name] = list
8
- else
9
- dsl(:enum_valid)[name]
10
- end
11
- end
12
-
13
- DEFAULT_ENUM_OPT_DESC = proc { |valid, default|
14
- I18n.t('i18n_tasks.cmd.enum_opt.desc', valid_text: valid, default_text: default)
15
- }
16
-
17
- def enum_opt_attr(short, long, valid, desc, error_msg)
18
- desc ||= DEFAULT_ENUM_OPT_DESC
19
- desc_proc = proc { desc.call(valid * ', ', I18n.t('i18n_tasks.cmd.args.default_text', value: valid.first)) }
20
- {short: short, long: long, desc: desc_proc,
21
- conf: {default: valid.first, argument: true, optional: false},
22
- parse: enum_parse_proc(:parse_enum_opt, valid, &error_msg)}
23
- end
24
-
25
- DEFAULT_LIST_OPT_DESC = proc { |valid, default|
26
- I18n.t('i18n_tasks.cmd.enum_list_opt.desc', valid_text: valid, default_text: default)
27
- }
28
-
29
- def enum_list_opt_attr(short, long, valid, desc, error_msg)
30
- desc ||= DEFAULT_LIST_OPT_DESC
31
- desc_proc = proc { desc.call(valid * ', ', I18n.t('i18n_tasks.cmd.args.default_all')) }
32
- {short: short, long: long, desc: desc_proc,
33
- conf: {as: Array, delimiter: /\s*[+:,]\s*/},
34
- parse: enum_parse_proc(:parse_enum_list_opt, valid, &error_msg)}
35
- end
36
-
37
- def enum_parse_proc(method, valid, &error)
38
- proc { |opt, key|
39
- opt[key] = send(method, opt[key], valid, &error)
40
- }
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,50 +0,0 @@
1
- module I18n::Tasks
2
- module Command
3
- module Options
4
- module EnumOpt
5
- DEFAULT_ENUM_OPT_ERROR = proc { |bad, good|
6
- I18n.t('i18n_tasks.cmd.enum_opt.invalid', invalid: bad, valid: good * ', ')
7
- }
8
-
9
- def parse_enum_opt(value, valid, &error_msg)
10
- valid = enum_opt(valid) if Symbol === valid
11
- return valid.first unless value.present?
12
- if enum_opt_valid?(valid, value)
13
- value
14
- else
15
- error_msg ||= DEFAULT_ENUM_OPT_ERROR
16
- raise CommandError.new error_msg.call(value, valid)
17
- end
18
- end
19
-
20
- def enum_opt_valid?(valid, value)
21
- valid = enum_opt(valid) if Symbol === valid
22
- valid.include?(value)
23
- end
24
-
25
- DEFAULT_ENUM_LIST_ERROR = proc { |bad, good|
26
- I18n.t('i18n_tasks.cmd.enum_list_opt.invalid', invalid: bad * ', ', valid: good * ', ')
27
- }
28
-
29
- def parse_enum_list_opt(values, valid, &error_msg)
30
- values = explode_list_opt(values)
31
- invalid = values - valid.map(&:to_s)
32
- if invalid.empty?
33
- if values.empty?
34
- valid
35
- else
36
- values
37
- end
38
- else
39
- error_msg ||= DEFAULT_ENUM_LIST_ERROR
40
- raise CommandError.new error_msg.call(invalid, valid)
41
- end
42
- end
43
-
44
- def enum_opt(*args)
45
- self.class.enum_opt(*args)
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,11 +0,0 @@
1
- module I18n::Tasks
2
- module Command
3
- module Options
4
- module ListOpt
5
- def explode_list_opt(list_opt, delim = /\s*[,]\s*/)
6
- Array(list_opt).compact.map { |v| v.strip.split(delim).compact.presence }.flatten.map(&:presence).compact
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,81 +0,0 @@
1
- module I18n::Tasks
2
- module Command
3
- module Options
4
- module Trees
5
- include Command::DSL
6
- format_opt = proc { |type|
7
- enum_opt_attr :f, :format=, enum_opt(type),
8
- proc { |valid, default|
9
- I18n.t("i18n_tasks.cmd.args.desc.#{type}", valid_text: valid, default_text: default) },
10
- proc { |value, valid|
11
- I18n.t('i18n_tasks.cmd.errors.invalid_format', invalid: value, valid: valid * ', ') }
12
- }
13
-
14
- enum_opt :data_format, %w(yaml json keys)
15
- # i18n-tasks-use t('i18n_tasks.cmd.args.desc.data_format')
16
- cmd_opt :data_format, format_opt.call(:data_format)
17
-
18
- enum_opt :out_format, ['terminal-table', *enum_opt(:data_format), 'inspect']
19
- # i18n-tasks-use t('i18n_tasks.cmd.args.desc.out_format')
20
- cmd_opt :out_format, format_opt.call(:out_format)
21
-
22
- def print_forest(forest, opt, version = :show_tree)
23
- format = opt[:format].to_s
24
- case format
25
- when 'terminal-table'
26
- terminal_report.send(version, forest)
27
- when 'inspect'
28
- puts forest.inspect
29
- when 'keys'
30
- puts forest.key_names(root: true)
31
- when *enum_opt(:data_format)
32
- puts i18n.data.adapter_dump forest.to_hash(true), format
33
- end
34
- end
35
-
36
- def opt_forest_arg_or_stdin!(opt, format = opt[:format])
37
- src = opt[:arguments].try(:shift) || $stdin.read
38
- parse_forest(src, format)
39
- end
40
-
41
- def opt_forests_stdin_args!(opt, num = false, format = opt[:format])
42
- args = opt[:arguments] || []
43
- if opt[:nostdin]
44
- sources = []
45
- else
46
- sources = [$stdin.read]
47
- num -= 1 if num
48
- end
49
- if num
50
- num.times { sources << args.shift }
51
- else
52
- sources += args
53
- args.clear
54
- end
55
- sources.map { |src| parse_forest(src, format) }
56
- end
57
-
58
- def opt_forests_merged_stdin_args!(opt)
59
- opt_forests_stdin_args!(opt).inject(i18n.empty_forest) { |result, forest|
60
- result.merge! forest
61
- }
62
- end
63
-
64
- def parse_forest(src, format)
65
- if !src
66
- raise CommandError.new(I18n.t('i18n_tasks.cmd.errors.pass_forest'))
67
- end
68
- if format == 'keys'
69
- Data::Tree::Siblings.from_key_names parse_keys(src)
70
- else
71
- Data::Tree::Siblings.from_nested_hash i18n.data.adapter_parse(src, format)
72
- end
73
- end
74
-
75
- def parse_keys(src)
76
- explode_list_opt(src, /\s*[,\s\n]\s*/)
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,41 +0,0 @@
1
- module I18n::Tasks::SlopCommand
2
- extend self
3
-
4
- def slop_command(name, attr, &block)
5
- proc {
6
- cmd_name = name.tr('_', '-')
7
- command cmd_name do
8
- args = attr[:args]
9
- banner "Usage: i18n-tasks #{cmd_name} [options] #{args}" if args.present?
10
- desc = attr[:desc]
11
- desc = desc.call if desc.respond_to?(:call)
12
- description desc if desc
13
- attr[:opt].try :each do |opt|
14
- on *opt.values_at(:short, :long, :desc, :conf).compact.map { |v| v.respond_to?(:call) ? v.call : v }
15
- end
16
- run { |slop_opts, slop_args|
17
- slop_opts = slop_opts.to_hash(true).reject { |k, v| v.nil? }
18
- slop_opts.merge!(arguments: slop_args) unless slop_args.empty?
19
- block.call name, slop_opts
20
- }
21
- end
22
- }
23
- end
24
-
25
- def parse_opts!(opts, opts_conf, context)
26
- return if !opts_conf
27
- opts_conf.each do |opt_conf|
28
- parse = opt_conf[:parse]
29
- if parse
30
- key = opt_conf[:long].to_s.sub(/=\z/, '').to_sym
31
- if parse.respond_to?(:call)
32
- context.instance_exec opts, key, &parse
33
- elsif Symbol === parse
34
- context.instance_exec do
35
- send parse, opts, key
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end