eco-helpers 3.0.37 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +132 -1
  4. data/lib/eco/api/common/loaders/base.rb +2 -2
  5. data/lib/eco/api/common/loaders/case_base.rb +2 -0
  6. data/lib/eco/api/common/loaders/config/block.rb +78 -0
  7. data/lib/eco/api/common/loaders/config/workflow/mailer.rb +49 -6
  8. data/lib/eco/api/common/loaders/config.rb +3 -26
  9. data/lib/eco/api/common/loaders/error_handler.rb +2 -0
  10. data/lib/eco/api/common/loaders/parser.rb +1 -4
  11. data/lib/eco/api/common/people/entries.rb +23 -6
  12. data/lib/eco/api/common/people/entry_factory.rb +1 -1
  13. data/lib/eco/api/common/people/person_entry.rb +104 -27
  14. data/lib/eco/api/common/people/person_parser.rb +50 -16
  15. data/lib/eco/api/common/people/supervisor_helpers.rb +12 -6
  16. data/lib/eco/api/common/session/base_session.rb +75 -81
  17. data/lib/eco/api/common/session/environment.rb +70 -70
  18. data/lib/eco/api/common/session/file_manager.rb +132 -135
  19. data/lib/eco/api/common/session/helpers/prompt_user.rb +23 -30
  20. data/lib/eco/api/common/session/helpers.rb +10 -15
  21. data/lib/eco/api/common/session/logger/cache.rb +94 -96
  22. data/lib/eco/api/common/session/logger/channels.rb +24 -32
  23. data/lib/eco/api/common/session/logger/log.rb +38 -46
  24. data/lib/eco/api/common/session/logger.rb +50 -54
  25. data/lib/eco/api/common/session/mailer/aws_provider.rb +64 -71
  26. data/lib/eco/api/common/session/mailer/provider_base.rb +43 -48
  27. data/lib/eco/api/common/session/mailer/sendgrid_provider.rb +101 -109
  28. data/lib/eco/api/common/session/mailer.rb +78 -83
  29. data/lib/eco/api/common/session/s3_uploader.rb +132 -138
  30. data/lib/eco/api/common/session/sftp.rb +202 -208
  31. data/lib/eco/api/common.rb +0 -3
  32. data/lib/eco/api/custom/mailer.rb +4 -2
  33. data/lib/eco/api/error/handlers.rb +1 -1
  34. data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +8 -2
  35. data/lib/eco/api/microcases/people/manage/search.rb +2 -2
  36. data/lib/eco/api/organization/people/similarity.rb +3 -3
  37. data/lib/eco/api/organization/people.rb +2 -2
  38. data/lib/eco/api/session/batch/base_policy.rb +42 -27
  39. data/lib/eco/api/session/batch/launcher/mode_size.rb +6 -1
  40. data/lib/eco/api/session/batch/launcher.rb +16 -3
  41. data/lib/eco/api/session/config/api.rb +4 -3
  42. data/lib/eco/api/session/config/apis/one_off.rb +1 -1
  43. data/lib/eco/api/session/config/files.rb +13 -12
  44. data/lib/eco/api/session/config/workflow.rb +1 -373
  45. data/lib/eco/api/session/config.rb +45 -10
  46. data/lib/eco/api/session.rb +7 -9
  47. data/lib/eco/api/usecases/base_case/model.rb +6 -6
  48. data/lib/eco/api/usecases/base_case.rb +1 -1
  49. data/lib/eco/api/usecases/cli.rb +1 -1
  50. data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +22 -13
  51. data/lib/eco/api/usecases/default_cases/to_csv_case.rb +4 -1
  52. data/lib/eco/api/usecases/graphql/helpers/location/tags_remap.rb +6 -3
  53. data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +2 -2
  54. data/lib/eco/api/usecases/lib/base/env.rb +21 -23
  55. data/lib/eco/api/usecases/lib/files/file_pattern.rb +41 -14
  56. data/lib/eco/api/usecases/lib/files/input_file.rb +110 -0
  57. data/lib/eco/api/usecases/lib/files/sftp.rb +5 -2
  58. data/lib/eco/api/usecases/lib/files.rb +1 -0
  59. data/lib/eco/api/usecases/lib/locations/base.rb +23 -0
  60. data/lib/eco/api/usecases/lib/locations/mapping.rb +94 -0
  61. data/lib/eco/api/usecases/lib/locations.rb +7 -0
  62. data/lib/eco/api/usecases/lib/people/base.rb +20 -0
  63. data/lib/eco/api/usecases/lib/people.rb +6 -0
  64. data/lib/eco/api/usecases/lib.rb +2 -0
  65. data/lib/eco/api/usecases/ooze_cases.rb +1 -1
  66. data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +1 -1
  67. data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +3 -3
  68. data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +4 -1
  69. data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +1 -1
  70. data/lib/eco/api/usecases/ooze_samples/register_export_case.rb +6 -2
  71. data/lib/eco/api/usecases/ooze_samples/register_migration_case.rb +7 -6
  72. data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +14 -4
  73. data/lib/eco/api/usecases/ooze_samples/target_oozes_update_case.rb +11 -8
  74. data/lib/eco/api/usecases/samples/drivers/sftp_sample.rb +2 -0
  75. data/lib/eco/api/usecases/samples/drivers/url_pull_sample.rb +8 -2
  76. data/lib/eco/api/usecases/service/sftp/with_target_config.rb +0 -33
  77. data/lib/eco/api/usecases/service/sftp.rb +7 -1
  78. data/lib/eco/api/usecases/use_case.rb +3 -2
  79. data/lib/eco/api/usecases/workflow.rb +5 -0
  80. data/lib/eco/api/usecases.rb +12 -5
  81. data/lib/eco/cli/scripting/args_helpers.rb +1 -9
  82. data/lib/eco/cli_default/options.rb +98 -68
  83. data/lib/eco/cli_default/workflow/end.rb +22 -0
  84. data/lib/eco/cli_default/workflow/launch_jobs.rb +14 -0
  85. data/lib/eco/cli_default/workflow/load/data.rb +27 -0
  86. data/lib/eco/cli_default/workflow/load/input.rb +28 -0
  87. data/lib/eco/cli_default/workflow/load.rb +13 -0
  88. data/lib/eco/cli_default/workflow/options.rb +18 -0
  89. data/lib/eco/cli_default/workflow/post_launch.rb +65 -0
  90. data/lib/eco/cli_default/workflow/report.rb +17 -0
  91. data/lib/eco/cli_default/workflow/rescued_exception.rb +21 -0
  92. data/lib/eco/cli_default/workflow/usecases.rb +23 -0
  93. data/lib/eco/cli_default/workflow.rb +24 -180
  94. data/lib/eco/data/count_trace.rb +51 -0
  95. data/lib/eco/data/files/content.rb +39 -0
  96. data/lib/eco/data/files/directory.rb +78 -45
  97. data/lib/eco/data/files/encoding.rb +12 -21
  98. data/lib/eco/data/files/file_pattern.rb +15 -8
  99. data/lib/eco/data/files/folder.rb +196 -0
  100. data/lib/eco/data/files/relative_path.rb +54 -0
  101. data/lib/eco/data/files/timestamp.rb +18 -0
  102. data/lib/eco/data/files.rb +46 -5
  103. data/lib/eco/data/fuzzy_match.rb +1 -1
  104. data/lib/eco/data/hashes/array_diff.rb +11 -5
  105. data/lib/eco/data/hashes/diff_result/meta.rb +12 -4
  106. data/lib/eco/data/locations/node_diff/accessors.rb +1 -1
  107. data/lib/eco/data/mapper.rb +8 -1
  108. data/lib/eco/data.rb +1 -0
  109. data/lib/eco/language/auxiliar_logger.rb +6 -11
  110. data/lib/eco/language/delegation/delegating_missing.rb +1 -1
  111. data/lib/eco/language/delegation/delegating_missing_const.rb +1 -1
  112. data/lib/eco/language/delegation/delegating_missing_on_class.rb +1 -1
  113. data/lib/eco/language/delegation/for_delegator/delegated_class.rb +1 -1
  114. data/lib/eco/language/klass/auto_loader.rb +129 -0
  115. data/lib/eco/language/klass/builder.rb +6 -6
  116. data/lib/eco/language/klass/const.rb +19 -0
  117. data/lib/eco/language/klass/helpers_built.rb +3 -1
  118. data/lib/eco/language/klass/hierarchy.rb +5 -1
  119. data/lib/eco/language/klass/naming.rb +5 -2
  120. data/lib/eco/language/klass/resolver.rb +21 -6
  121. data/lib/eco/language/klass/uid.rb +12 -0
  122. data/lib/eco/language/klass/when_inherited.rb +30 -6
  123. data/lib/eco/language/klass.rb +5 -2
  124. data/lib/eco/language/methods/access_modifier.rb +23 -0
  125. data/lib/eco/language/methods/instance_method_helpers.rb +6 -1
  126. data/lib/eco/language/methods.rb +1 -0
  127. data/lib/eco/language/models/hierarchy.rb +41 -0
  128. data/lib/eco/language/models/workflow.rb +385 -0
  129. data/lib/eco/language/models.rb +2 -1
  130. data/lib/eco/version.rb +1 -1
  131. metadata +31 -7
  132. data/lib/eco/api/common/class_auto_loader.rb +0 -114
  133. data/lib/eco/api/common/class_helpers.rb +0 -9
  134. data/lib/eco/api/common/class_hierarchy.rb +0 -45
  135. data/lib/eco/data/files/helpers.rb +0 -152
  136. data/lib/eco/language/models/class_helpers.rb +0 -136
@@ -2,7 +2,7 @@
2
2
  # @note
3
3
  # - `target_ids` => Expects options[:source][:file] where at least the 1st column should be the target entry `ids`
4
4
  class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCases::OozeSamples::RegisterUpdateCase
5
- name "target-oozes-update-case"
5
+ name 'target-oozes-update-case'
6
6
  type :other
7
7
 
8
8
  private
@@ -24,12 +24,15 @@ class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCase
24
24
  log(:warn) { "Could not get page #{id}" }
25
25
  end
26
26
  end
27
+
27
28
  update_oozes
28
29
  end
29
30
  end
30
31
 
31
32
  def batched_target_ids
32
- raise "Missing block. It yields in slices of #{self.class.batch_size} ids" unless block_given?
33
+ msg = "Missing block. It yields in slices of #{self.class.batch_size} ids"
34
+ raise ArgumentError, msg unless block_given?
35
+
33
36
  target_ids_preview
34
37
  pool = []
35
38
  target_ids.each do |id|
@@ -47,20 +50,20 @@ class Eco::API::UseCases::OozeSamples::TargetOozesUpdateCase < Eco::API::UseCase
47
50
  @total_search_oozes = target_ids.count
48
51
  @dupped_search_oozes = dups.count
49
52
 
50
- dups_str = dups.count.positive? ? "There are #{dups.count} duplicated ids" : "No duplicates detected"
53
+ dups_str = dups.count.positive? ? "There are #{dups.count} duplicated ids" : 'No duplicates detected'
51
54
  msg = "Total target entries: #{target_ids.count} (#{dups_str})"
52
55
 
53
- default_answer = session.config.run_mode_remote?? "Y" : "N"
56
+ default_answer = session.config.run_mode_remote?? 'Y' : 'N'
54
57
 
55
58
  session.prompt_user(
56
- "Do you want to proceed (y/N):",
59
+ 'Do you want to proceed (y/N):',
57
60
  explanation: msg,
58
61
  default: default_answer,
59
62
  timeout: 10
60
63
  ) do |res|
61
- unless res.upcase.start_with?("Y")
62
- puts "..."
63
- log(:info) { "Aborting script..." }
64
+ unless res.upcase.start_with?('Y')
65
+ puts '...'
66
+ log(:info) { 'Aborting script...' }
64
67
  exit(0)
65
68
  end
66
69
  end
@@ -57,6 +57,8 @@ class Eco::API::UseCases::Samples::Drivers::Sftp < Eco::API::Common::Loaders::Us
57
57
  end
58
58
  end
59
59
 
60
+ # @todo when `sftp_move_file` fails, it still `puts` the message
61
+ # that it moved the file(s) to the `archive_subfolder`
60
62
  def archive_files
61
63
  with_remote_files(pattern: file_pattern) do |file|
62
64
  source = to_remote_path(file.name) # should probably be file.longname
@@ -62,7 +62,12 @@ class Eco::API::UseCases::Samples::Drivers::UrlPull < Eco::API::Common::Loaders:
62
62
  end
63
63
 
64
64
  def http_start(uri, &block)
65
- Net::HTTP.start(uri.hostname, uri.port, request_options(uri), &block)
65
+ Net::HTTP.start(
66
+ uri.hostname,
67
+ uri.port,
68
+ request_options(uri),
69
+ &block
70
+ )
66
71
  end
67
72
 
68
73
  def base_request(uri, user: nil, pass: '')
@@ -95,7 +100,8 @@ class Eco::API::UseCases::Samples::Drivers::UrlPull < Eco::API::Common::Loaders:
95
100
 
96
101
  def target_url_const
97
102
  if (fpc = options.dig(:url_pull, :target_url_const))
98
- raise WrongConst, "(#{self.class}) Invalid file pattern const referral: #{fpc}" unless fpc.match(CONST_REFERRAL)
103
+ msg = "(#{self.class}) Invalid file pattern const referral: #{fpc}"
104
+ raise WrongConst, msg unless fpc.match(CONST_REFERRAL)
99
105
 
100
106
  begin
101
107
  self.eval(fpc)
@@ -36,39 +36,6 @@ module Eco::API::UseCases::Service
36
36
  self.class::ENV_PATHS if self.class.const_defined?(:ENV_PATHS)
37
37
  end
38
38
  end
39
-
40
- # module ClassMethods
41
- # def wrap_with_target_sftp(*mtds)
42
- # mtds.map(&:to_sym).each do |method_name|
43
- # msg = "#{self} does not have instance method '#{method_name}'"
44
- # has_method = instance_method?(name: method_name, include_private: true, inherited: true)
45
- # raise ArgumentError, msg unless has_method
46
- #
47
- # method_was_inherited = instance_inherited_method?(name: method_name)
48
- # method_is_public = instance_method?(name: method_name, include_private: false)
49
- # original_method = :"method_to_wrap_with_target_sftp_#{method_name}"
50
- #
51
- # # don't over-override
52
- # next if instance_method?(name: original_method, include_private: true, inherited: true)
53
- #
54
- # method_def = proc do |*args, **kargs, &block|
55
- # with_target_sftp_config do
56
- # if method_was_inherited
57
- # super(*args, **kargs, &block)
58
- # else
59
- # send(original_method, *args, **kargs, &block)
60
- # end
61
- # end
62
- # end
63
- #
64
- # alias_method(original_method, method_name) unless method_was_inherited
65
- # define_method(method_name, &method_def)
66
- # private method_name unless method_is_public
67
- # end
68
- #
69
- # self
70
- # end
71
- # end
72
39
  end
73
40
  end
74
41
  end
@@ -1,9 +1,15 @@
1
1
  require_relative 'sftp/with_target_config'
2
2
  module Eco::API::UseCases::Service
3
3
  # Class that pulls configuration from the subject (i.e. `remote_folder`)
4
+ # @note It accepts modify the targt SFTP in subclasses by defining two constants:
5
+ # - `BASE_PATH` (String)
6
+ # - `ENV_PATHS` (Hash)
7
+ # @note it makes public all methods of the `Files::Sftp` module.
4
8
  class Sftp
9
+ include Eco::Language::Methods::AccessModifier
5
10
  include Eco::API::UseCases::Lib::Files::Sftp
6
- public(*Eco::API::UseCases::Lib::Files::Sftp.private_instance_methods(inherited: false))
11
+
12
+ make_public_all from: Eco::API::UseCases::Lib::Files::Sftp, inherited: false
7
13
 
8
14
  include WithTargetConfig
9
15
 
@@ -26,7 +26,7 @@ module Eco
26
26
  end
27
27
 
28
28
  def source_object
29
- return nil unless callback_from_loader?
29
+ return unless callback_from_loader?
30
30
 
31
31
  callback_self
32
32
  end
@@ -77,7 +77,7 @@ module Eco
77
77
  attr_reader :callback
78
78
 
79
79
  def callback_self
80
- eval("self", callback.binding, __FILE__, __LINE__)
80
+ eval('self', callback.binding, __FILE__, __LINE__)
81
81
  end
82
82
 
83
83
  def callback_from_loader?
@@ -86,6 +86,7 @@ module Eco
86
86
 
87
87
  # Set the instance variables `@session` and `@options`
88
88
  # in the use case definition
89
+ # @todo check if this method shouldn't really just be part of `uio`
89
90
  # @note this only works when the use case was defined
90
91
  # via an children class of `Eco::API::Common::Loaders::Base`
91
92
  def set_session_n_options(uio) # rubocop:disable Naming/AccessorMethodName
@@ -0,0 +1,5 @@
1
+ class Eco::API::UseCases
2
+ class Workflow < Eco::Language::Models::Workflow
3
+ INPUT_OUTPUT_CLASS = Eco::API::UseCases::BaseIO
4
+ end
5
+ end
@@ -19,7 +19,7 @@ module Eco
19
19
  end
20
20
  end
21
21
 
22
- extend Eco::API::Common::ClassAutoLoader
22
+ extend Eco::Language::Klass::AutoLoader
23
23
  include Enumerable
24
24
 
25
25
  autoloads_children_of 'Eco::API::Common::Loaders::UseCase'
@@ -29,6 +29,7 @@ module Eco
29
29
  @usecases = {}
30
30
  @cache_init = false
31
31
  @cases_by_name = {}
32
+
32
33
  init_caches
33
34
  end
34
35
 
@@ -52,6 +53,7 @@ module Eco
52
53
 
53
54
  def defined?(name, type: nil)
54
55
  return to_h.key?(key(name, type)) if type
56
+
55
57
  name?(name)
56
58
  end
57
59
 
@@ -83,7 +85,8 @@ module Eco
83
85
  puts "Warning: overriding '#{type}' case #{name}" if self.defined?(name, type: type)
84
86
 
85
87
  to_h[key(name, type)] = usecase
86
- @cache_init = false
88
+ @cache_init = false
89
+
87
90
  usecase
88
91
  end
89
92
 
@@ -102,7 +105,9 @@ module Eco
102
105
  msg = "Expected a Eco::API::UseCases object. Given #{cases.class}"
103
106
  raise msg unless cases.is_a?(Eco::API::UseCases)
104
107
 
105
- to_h.merge!(cases.to_h).transform_values do |usecase|
108
+ to_h.merge!(
109
+ cases.to_h
110
+ ).transform_values do |usecase|
106
111
  usecase.root = self
107
112
  end
108
113
 
@@ -126,6 +131,7 @@ module Eco
126
131
  elsif type
127
132
  raise UseCases::UnknownCase.new(case_name: name, type: type)
128
133
  end
134
+
129
135
  raise UseCases::UnknownCase.new(case_name: name, type: type) unless (cases = by_name[name])
130
136
  raise UseCases::AmbiguousCaseReference.new(case_name: name) if cases.length > 1
131
137
 
@@ -148,10 +154,10 @@ module Eco
148
154
 
149
155
  def init_caches
150
156
  # first, make sure it loads pending `:custom_children` children to be loaded
151
- re_init = self.class.autoload_children(self)
157
+ re_init = self.class.autoload_children!(self)
152
158
  return true if @cache_init && !re_init
153
159
 
154
- @by_name = @usecases.values.group_by(&:name)
160
+ @by_name = @usecases.values.group_by(&:name)
155
161
  @cache_init = true
156
162
  end
157
163
 
@@ -176,6 +182,7 @@ require_relative 'usecases/use_case_chain'
176
182
  require_relative 'usecases/base_io'
177
183
  require_relative 'usecases/use_case_io'
178
184
  require_relative 'usecases/cli'
185
+ require_relative 'usecases/workflow'
179
186
  require_relative 'usecases/lib'
180
187
  require_relative 'usecases/service'
181
188
  require_relative 'usecases/graphql'
@@ -105,7 +105,7 @@ module Eco
105
105
  if required && !filename
106
106
  puts "You need to specify a file or folder '#{key} file_or_folder'"
107
107
  exit(1)
108
- elsif should_exist && filename && !file_exists?(filename)
108
+ elsif should_exist && filename && !File.exist?(filename)
109
109
  puts "This file/folder doesn't exist '#{filename}'"
110
110
  exit(1)
111
111
  end
@@ -113,14 +113,6 @@ module Eco
113
113
  filename = File.expand_path(filename) if filename && should_exist
114
114
  filename
115
115
  end
116
-
117
- private
118
-
119
- def file_exists?(filename)
120
- return false if filename.nil?
121
-
122
- File.exist?(filename) || File.exist?(File.expand_path(filename))
123
- end
124
116
  end
125
117
  end
126
118
  end
@@ -1,6 +1,6 @@
1
1
  ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
2
2
  cnf.options_set do |options_set, top_opts| # rubocop:disable Metrics/BlockLength
3
- options_set.add('--help', 'Offers a HELP') do |options, _sess|
3
+ options_set.add('--help', 'Offers a HELP') do |_opts, _sess|
4
4
  conf = ASSETS.cli.config
5
5
 
6
6
  active = proc do |opt|
@@ -54,6 +54,67 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
54
54
  $stdout.reopen(file, 'w+')
55
55
  end
56
56
 
57
+ desc = 'Runs in dry-run (no requests sent to server)'
58
+ options_set.add(['-dry-run', '-simulate'], desc) do |options, session|
59
+ options[:dry_run] = true
60
+ options[:simulate] = true
61
+ session.config.dry_run!
62
+ end
63
+
64
+ desc = 'Specifies the target API key space (i.e. uat, dev, etc.). '
65
+ desc << 'Use with CAUTION !!!'
66
+ options_set.add('-space', desc) do |options, _sess|
67
+ next unless (space = SCR.get_arg('-space', with_param: true))
68
+
69
+ options.deep_merge!(api: {space: space.to_sym})
70
+ end
71
+
72
+ desc = "It specifies the type of batch to be used (default: ':batch')"
73
+ options_set.add('-batch-mode', desc) do |options, session|
74
+ mode_in = SCR.get_arg('-batch-mode', with_param: true)
75
+ mode_str = mode_in.to_s.downcase
76
+ mode_sym = %i[batch job].find do |md|
77
+ next true if md.to_s == mode_str
78
+
79
+ md.to_s == mode_str.gsub(':', '')
80
+ end
81
+
82
+ unless mode_sym
83
+ session.log(:warn) {
84
+ "Unknown job_mode: #{mode_in}. Switching to default: ':batch'"
85
+ }
86
+ mode_sym = :batch
87
+ end
88
+
89
+ options.deep_merge!(workflow: {batch: {mode: mode_sym}})
90
+ end
91
+
92
+ # EMAIL NOTIFICATIONS & INVITES
93
+
94
+ desc = 'Prevent email to be sent'
95
+ options_set.add('-no-email', desc) do |options|
96
+ options.deep_merge!(workflow: {no_email: true})
97
+ end
98
+
99
+ desc = 'Do not prevent email notification when not in remote or when in dry run'
100
+ options_set.add('-notify', desc) do |options|
101
+ options.deep_merge!(workflow: {notify: true})
102
+ options.deep_merge!(workflow: {no_mail: false})
103
+ end
104
+
105
+
106
+ desc = 'Silence notifications on account creation or invites'
107
+ options_set.add(['-no-invites', '-exclude-invites'], desc) do |options|
108
+ options.merge!(send_invites: false)
109
+ end
110
+
111
+ desc = "People with account will be reinvited if they haven't accepted the invitation"
112
+ options_set.add('-send-invites', desc) do |options|
113
+ options.merge!(send_invites: true)
114
+ end
115
+
116
+ # CSV
117
+
57
118
  desc = 'Skips the check of the headers'
58
119
  options_set.add('-skip-header-check', desc) do |options, _sess|
59
120
  options.deep_merge!(input: {header_check: {skip: true}})
@@ -69,26 +130,7 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
69
130
  options.deep_merge!(input: {header_check: {must_be_valid: true}})
70
131
  end
71
132
 
72
- desc = 'Fix the current session to work with this schema'
73
- options_set.add('-schema-id', desc) do |options, session|
74
- sch_name = SCR.get_arg('-schema-id', with_param: true)
75
- sch_id = session.schemas.to_id(sch_name)
76
-
77
- unless sch_id
78
- msg = 'You need to specify a correct schema id or name. '
79
- msg << "'#{sch_name}' does not exist. Correct options are: "
80
- msg << session.schemas.map(&:name).join(', ')
81
-
82
- session.log(:error) { msg }
83
- exit(1)
84
- end
85
-
86
- options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}})
87
- session.log(:info) {
88
- "Setting schema #{session.schemas.to_name(sch_id)}"
89
- }
90
- session.schema = sch_id
91
- end
133
+ # INPUT MODIFIERS
92
134
 
93
135
  desc = 'Used to be used to specify the input file or folder when using -get-partial. '
94
136
  desc << 'It can also be useful to obtain `-get-partial` of people base on `:export` use cases (i.e. -people-to-csv)'
@@ -98,11 +140,13 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
98
140
 
99
141
  desc = 'Used to specify the input file encoding'
100
142
  options_set.add('-input-encoding', desc) do |options, _sess|
101
- if encoding = SCR.get_arg('-input-encoding', with_param: true)
143
+ if (encoding = SCR.get_arg('-input-encoding', with_param: true))
102
144
  options.deep_merge!(input: {file: {encoding: encoding}})
103
145
  end
104
146
  end
105
147
 
148
+ # PEOPLE FETCH
149
+
106
150
  desc = 'Do not load any people for this run.'
107
151
  options_set.add('-no-people', desc) do |options, _sess|
108
152
  options.deep_merge!(people: {
@@ -131,11 +175,6 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
131
175
  })
132
176
  end
133
177
 
134
- desc = "Saves the requests's body even though running in dry-run (-simulate)"
135
- options_set.add('-save-requests', desc) do |options, _sess|
136
- options.deep_merge!(requests: {backup: true})
137
- end
138
-
139
178
  desc = 'Used to specify the cache file of people to be used. '
140
179
  desc << 'It is useful to use as people reference those stored in cached file diffrent to the last one.'
141
180
  options_set.add('-people-from-backup', desc) do |options, _sess|
@@ -156,46 +195,45 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
156
195
  options.deep_merge!(report: {people: {csv: file}})
157
196
  end
158
197
 
159
- desc = 'Runs in dry-run (no requests sent to server)'
160
- options_set.add(['-dry-run', '-simulate'], desc) do |options, session|
161
- options[:dry_run] = true
162
- options[:simulate] = true
163
- session.config.dry_run!
164
- end
165
-
166
- desc = 'Specifies the target API key space (i.e. uat, dev, etc.). '
167
- desc << 'Use with CAUTION !!!'
168
- options_set.add('-space', desc) do |options, _sess|
169
- next unless (space = SCR.get_arg('-space', with_param: true))
198
+ # Filter by schema
170
199
 
171
- options.deep_merge!(api: {space: space.to_sym})
172
- end
200
+ desc = 'Fix the current session to work with this schema'
201
+ options_set.add('-schema-id', desc) do |options, session|
202
+ sch_name = SCR.get_arg('-schema-id', with_param: true)
203
+ sch_id = session.schemas.to_id(sch_name)
173
204
 
174
- desc = "It specifies the type of batch to be used (default: ':batch')"
175
- options_set.add('-batch-mode', desc) do |options, session|
176
- mode_in = SCR.get_arg('-batch-mode', with_param: true)
177
- mode_str = mode_in.to_s.downcase
178
- mode_sym = %i[batch job].find do |md|
179
- next true if md.to_s == mode_str
205
+ unless sch_id
206
+ msg = 'You need to specify a correct schema id or name. '
207
+ msg << "'#{sch_name}' does not exist. Correct options are: "
208
+ msg << session.schemas.map(&:name).join(', ')
180
209
 
181
- md.to_s == mode_str.gsub(':', '')
210
+ session.log(:error) { msg }
211
+ exit(1)
182
212
  end
183
213
 
184
- unless mode_sym
185
- session.log(:warn) {
186
- "Unknown job_mode: #{mode_in}. Switching to default: ':batch'"
187
- }
188
- mode_sym = :batch
189
- end
214
+ options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}})
215
+ session.log(:info) {
216
+ "Setting schema #{session.schemas.to_name(sch_id)}"
217
+ }
218
+ session.schema = sch_id
219
+ end
190
220
 
191
- options.deep_merge!(workflow: {batch: {mode: mode_sym}})
221
+ # REQUESTS
222
+
223
+ desc = "Saves the requests's body even though running in dry-run (-simulate)"
224
+ options_set.add('-save-requests', desc) do |options, _sess|
225
+ options.deep_merge!(requests: {backup: true})
192
226
  end
193
227
 
228
+ # WORKFLOW
229
+
194
230
  desc = 'Runs runs post_launch cases even if in dry-run'
195
231
  options_set.add('-run-postlaunch', desc) do |options, _sess|
196
232
  options.deep_merge!(post_launch: {run: true})
197
233
  end
198
234
 
235
+ # INCLUDED
236
+
199
237
  desc = '(careful with this option) This will include everybody as part of the update '
200
238
  desc << '(including those that are api excluded). '
201
239
  desc << 'Only launch with this option when only api excluded people are included in your update.'
@@ -208,6 +246,8 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
208
246
  options.deep_merge!(include: {excluded: {only: true}})
209
247
  end
210
248
 
249
+ # BATCH POLCIY & API POLICIES
250
+
211
251
  desc = 'Ignores threshold limitations on requests for this session (skip batch belt)'
212
252
  options_set.add('-skip-batch-policy', desc) do |options|
213
253
  options.deep_merge!(skip: {batch_policy: true})
@@ -218,10 +258,14 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
218
258
  options.deep_merge!(skip: {api_policies: true})
219
259
  end
220
260
 
261
+ # FEEDBACK
262
+
221
263
  options_set.add('-feed-only-stats', 'Shows only stats when giving feedback') do |options|
222
264
  options.deep_merge!(feedback: {only_stats: true})
223
265
  end
224
266
 
267
+ # STRICT/SOFT SEARCH MATCH
268
+
225
269
  desc = "Force search mode to 'strict' when pairing input entries with existing people."
226
270
  desc << ' Besides id and external_id it will not try to find by email unless external_id is not specified'
227
271
  options_set.add('-search-strict', desc) do |options|
@@ -238,20 +282,6 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
238
282
  })
239
283
  end
240
284
 
241
- desc = 'Prevent email to be sent (experimental)'
242
- options_set.add('-no-email', desc) do |options|
243
- options.deep_merge!(workflow: {no_email: true})
244
- end
245
-
246
- desc = 'Silence notifications on account creation or invites'
247
- options_set.add(['-no-invites', '-exclude-invites'], desc) do |options|
248
- options.merge!(send_invites: false)
249
- end
250
- desc = "People with account will be reinvited if they haven't accepted the invitation"
251
- options_set.add('-send-invites', desc) do |options|
252
- options.merge!(send_invites: true)
253
- end
254
-
255
285
  # EXCLUDE CORE
256
286
 
257
287
  options_set.add('-exclude-core', 'Core input data is not used on the update') do |options|
@@ -0,0 +1,22 @@
1
+ class Eco::CliDefault::Workflow
2
+ class End < Eco::API::Common::Loaders::Workflow
3
+ config_block(:workflow, :end) do
4
+ on(:end) do
5
+ get_people = options.dig(:people, :get)
6
+ partial_update = get_people && get_people[:type] == :partial
7
+
8
+ unless !options[:end_get] || options[:dry_run] || partial_update
9
+ if !some_update_case?(io)
10
+ # Prevent getting people when there were no use cases that used them
11
+ log(:info) {
12
+ "Won't be recaching people, as there haven't been any targetted updates"
13
+ }
14
+ elsif !people
15
+ people = session.micro.people_cache
16
+ io.new(data: people)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ class Eco::CliDefault::Workflow
2
+ class LaunchJobs < Eco::API::Common::Loaders::Workflow
3
+ config_block(:workflow, :launch_jobs) do
4
+ before(:launch_jobs) do
5
+ available_args = cli.config.available_option_args
6
+ SCR.stop_on_unknown!(all_available: available_args)
7
+ end
8
+
9
+ on(:launch_jobs) do
10
+ session.jobs_launch(simulate: options[:dry_run])
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ class Eco::CliDefault::Workflow::Load
2
+ class Data < Eco::API::Common::Loaders::Workflow
3
+ config_block(:workflow, :load, :data) do
4
+ with(:load) do |wf_load|
5
+ wf_load.before(:data) do
6
+ # @todo model should be set to the target model
7
+ # based on the main use case that requires data!
8
+ io.new(model: :people)
9
+ end
10
+
11
+ wf_load.with(:data) do |wf_peo|
12
+ wf_peo.on(:get) do
13
+ next unless some_data_case?(io) || options.dig(:people, :get)
14
+
15
+ io.new(data: cli.config.people(io: io))
16
+ end
17
+
18
+ wf_peo.on(:filter) do
19
+ next unless data && !data.empty?
20
+
21
+ io.new(data: cli.config.people_filters.process(io: io))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ class Eco::CliDefault::Workflow::Load
2
+ class Input < Eco::API::Common::Loaders::Workflow
3
+ config_block(:workflow, :load, :input) do
4
+ with(:load) do |wf_load|
5
+ wf_load.with(:input) do |wf_in|
6
+ wf_in.on(:get) do
7
+ input_is_required = some_input_case?(io) || options.dig(:input, :entries_from)
8
+ missing_input = !input || input.empty?
9
+ next unless missing_input && input_is_required
10
+
11
+ if options.dig(:input, :entries_from)
12
+ io.new(input: cli.config.input.get(io: io))
13
+ else
14
+ opt_case = cli_input_cases(io).values.first.option
15
+ io.new(input: cli.config.input.get(io: io, option: opt_case))
16
+ end
17
+ end
18
+
19
+ wf_in.on(:filter) do
20
+ next unless input && !input.empty?
21
+
22
+ io.new(input: cli.config.input_filters.process(io: io))
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ class Eco::CliDefault::Workflow
2
+ class Load < Eco::API::Common::Loaders::Workflow
3
+ require_relative 'load/input'
4
+ require_relative 'load/data'
5
+
6
+ [
7
+ Input,
8
+ Data
9
+ ].each do |wf_config|
10
+ wf_config.config_copy(to: self, all: true)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ class Eco::CliDefault::Workflow
2
+ class Options < Eco::API::Common::Loaders::Workflow
3
+ config_block(:workflow, :options) do
4
+ on(:options) do
5
+ cli_usecases.cli_apply(io: io)
6
+ io.new(options: cli.config.options_set.process(io: io))
7
+ end
8
+
9
+ after(:options) do
10
+ next unless session.config.dry_run?
11
+
12
+ session.log(:general) {
13
+ 'Running in dry-run mode (simulate).'
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end