dtk-shell 0.10.0

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 (191) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile_dev +13 -0
  4. data/README.md +121 -0
  5. data/bin/dtk-execute +32 -0
  6. data/bin/dtk-run +92 -0
  7. data/bin/dtk-shell +31 -0
  8. data/dtk-shell.gemspec +50 -0
  9. data/lib/auxiliary.rb +61 -0
  10. data/lib/bundler_monkey_patch.rb +26 -0
  11. data/lib/client.rb +58 -0
  12. data/lib/command_helper.rb +33 -0
  13. data/lib/command_helpers/git_repo.rb +589 -0
  14. data/lib/command_helpers/git_repo/merge.rb +153 -0
  15. data/lib/command_helpers/jenkins_client.rb +106 -0
  16. data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
  17. data/lib/command_helpers/service_importer.rb +251 -0
  18. data/lib/command_helpers/service_link.rb +33 -0
  19. data/lib/command_helpers/test_module_creator.rb +69 -0
  20. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
  21. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
  22. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
  23. data/lib/commands.rb +57 -0
  24. data/lib/commands/common/thor/access_control.rb +133 -0
  25. data/lib/commands/common/thor/action_result_handler.rb +74 -0
  26. data/lib/commands/common/thor/assembly_template.rb +92 -0
  27. data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
  28. data/lib/commands/common/thor/base_command_helper.rb +59 -0
  29. data/lib/commands/common/thor/clone.rb +82 -0
  30. data/lib/commands/common/thor/common.rb +88 -0
  31. data/lib/commands/common/thor/common_base.rb +49 -0
  32. data/lib/commands/common/thor/create_target.rb +70 -0
  33. data/lib/commands/common/thor/edit.rb +255 -0
  34. data/lib/commands/common/thor/inventory_parser.rb +98 -0
  35. data/lib/commands/common/thor/list_diffs.rb +128 -0
  36. data/lib/commands/common/thor/module.rb +1011 -0
  37. data/lib/commands/common/thor/module/import.rb +210 -0
  38. data/lib/commands/common/thor/node.rb +53 -0
  39. data/lib/commands/common/thor/poller.rb +65 -0
  40. data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
  41. data/lib/commands/common/thor/pull_from_remote.rb +152 -0
  42. data/lib/commands/common/thor/puppet_forge.rb +72 -0
  43. data/lib/commands/common/thor/purge_clone.rb +101 -0
  44. data/lib/commands/common/thor/push_clone_changes.rb +162 -0
  45. data/lib/commands/common/thor/push_to_remote.rb +94 -0
  46. data/lib/commands/common/thor/remotes.rb +71 -0
  47. data/lib/commands/common/thor/reparse.rb +40 -0
  48. data/lib/commands/common/thor/set_required_attributes.rb +46 -0
  49. data/lib/commands/thor/account.rb +239 -0
  50. data/lib/commands/thor/assembly.rb +356 -0
  51. data/lib/commands/thor/attribute.rb +79 -0
  52. data/lib/commands/thor/component.rb +70 -0
  53. data/lib/commands/thor/component_module.rb +501 -0
  54. data/lib/commands/thor/component_template.rb +174 -0
  55. data/lib/commands/thor/dependency.rb +34 -0
  56. data/lib/commands/thor/developer.rb +144 -0
  57. data/lib/commands/thor/dtk.rb +152 -0
  58. data/lib/commands/thor/library.rb +125 -0
  59. data/lib/commands/thor/node.rb +504 -0
  60. data/lib/commands/thor/node_template.rb +94 -0
  61. data/lib/commands/thor/project.rb +34 -0
  62. data/lib/commands/thor/provider.rb +233 -0
  63. data/lib/commands/thor/remotes.rb +49 -0
  64. data/lib/commands/thor/service.rb +941 -0
  65. data/lib/commands/thor/service_module.rb +914 -0
  66. data/lib/commands/thor/state_change.rb +25 -0
  67. data/lib/commands/thor/target.rb +250 -0
  68. data/lib/commands/thor/task.rb +116 -0
  69. data/lib/commands/thor/test_module.rb +310 -0
  70. data/lib/commands/thor/utils.rb +21 -0
  71. data/lib/commands/thor/workspace.rb +685 -0
  72. data/lib/config/cacert.pem +3785 -0
  73. data/lib/config/client.conf.header +20 -0
  74. data/lib/config/configuration.rb +99 -0
  75. data/lib/config/default.conf +16 -0
  76. data/lib/config/disk_cacher.rb +80 -0
  77. data/lib/configurator.rb +176 -0
  78. data/lib/context_router.rb +44 -0
  79. data/lib/core.rb +497 -0
  80. data/lib/domain/git_adapter.rb +412 -0
  81. data/lib/domain/git_error_handler.rb +64 -0
  82. data/lib/domain/response.rb +285 -0
  83. data/lib/domain/response/error_handler.rb +86 -0
  84. data/lib/dtk-shell/version.rb +20 -0
  85. data/lib/dtk_constants.rb +40 -0
  86. data/lib/dtk_error.rb +114 -0
  87. data/lib/dtk_logger.rb +126 -0
  88. data/lib/dtk_shell.rb +31 -0
  89. data/lib/error.rb +85 -0
  90. data/lib/execute.rb +29 -0
  91. data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
  92. data/lib/execute/command.rb +40 -0
  93. data/lib/execute/command/api_call.rb +60 -0
  94. data/lib/execute/command/api_call/map.rb +60 -0
  95. data/lib/execute/command/api_call/service.rb +91 -0
  96. data/lib/execute/command/api_call/translation_term.rb +119 -0
  97. data/lib/execute/command/rest_call.rb +37 -0
  98. data/lib/execute/command_processor.rb +30 -0
  99. data/lib/execute/command_processor/rest_call.rb +59 -0
  100. data/lib/execute/error_usage.rb +21 -0
  101. data/lib/execute/execute_context.rb +86 -0
  102. data/lib/execute/execute_context/result_store.rb +37 -0
  103. data/lib/execute/script.rb +64 -0
  104. data/lib/execute/script/add_tenant.rb +121 -0
  105. data/lib/git-logs/git.log +0 -0
  106. data/lib/parser/adapters/option_parser.rb +70 -0
  107. data/lib/parser/adapters/thor.rb +555 -0
  108. data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
  109. data/lib/require_first.rb +104 -0
  110. data/lib/search_hash.rb +44 -0
  111. data/lib/shell.rb +261 -0
  112. data/lib/shell/context.rb +1065 -0
  113. data/lib/shell/context_aux.rb +46 -0
  114. data/lib/shell/domain/active_context.rb +186 -0
  115. data/lib/shell/domain/context_entity.rb +89 -0
  116. data/lib/shell/domain/context_params.rb +223 -0
  117. data/lib/shell/domain/override_tasks.rb +88 -0
  118. data/lib/shell/domain/shadow_entity.rb +76 -0
  119. data/lib/shell/header_shell.rb +44 -0
  120. data/lib/shell/help_monkey_patch.rb +283 -0
  121. data/lib/shell/interactive_wizard.rb +225 -0
  122. data/lib/shell/message_queue.rb +63 -0
  123. data/lib/shell/parse_monkey_patch.rb +39 -0
  124. data/lib/shell/status_monitor.rb +124 -0
  125. data/lib/task_status.rb +83 -0
  126. data/lib/task_status/refresh_mode.rb +77 -0
  127. data/lib/task_status/snapshot_mode.rb +28 -0
  128. data/lib/task_status/stream_mode.rb +48 -0
  129. data/lib/task_status/stream_mode/element.rb +101 -0
  130. data/lib/task_status/stream_mode/element/format.rb +101 -0
  131. data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
  132. data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
  133. data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
  134. data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
  135. data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
  136. data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
  137. data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
  138. data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
  139. data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
  140. data/lib/task_status/stream_mode/element/no_results.rb +26 -0
  141. data/lib/task_status/stream_mode/element/render.rb +59 -0
  142. data/lib/task_status/stream_mode/element/stage.rb +84 -0
  143. data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
  144. data/lib/task_status/stream_mode/element/task_end.rb +35 -0
  145. data/lib/task_status/stream_mode/element/task_start.rb +37 -0
  146. data/lib/util/common_util.rb +37 -0
  147. data/lib/util/console.rb +235 -0
  148. data/lib/util/dtk_puppet.rb +65 -0
  149. data/lib/util/module_util.rb +66 -0
  150. data/lib/util/os_util.rb +385 -0
  151. data/lib/util/permission_util.rb +31 -0
  152. data/lib/util/remote_dependency_util.rb +84 -0
  153. data/lib/util/ssh_util.rb +94 -0
  154. data/lib/view_processor.rb +129 -0
  155. data/lib/view_processor/augmented_simple_list.rb +44 -0
  156. data/lib/view_processor/hash_pretty_print.rb +123 -0
  157. data/lib/view_processor/simple_list.rb +156 -0
  158. data/lib/view_processor/table_print.rb +309 -0
  159. data/lib/violation.rb +86 -0
  160. data/lib/violation/attribute.rb +76 -0
  161. data/lib/violation/fix.rb +26 -0
  162. data/lib/violation/fix/result.rb +73 -0
  163. data/lib/violation/fix/result/error.rb +34 -0
  164. data/lib/violation/fix/set_attribute.rb +41 -0
  165. data/lib/violation/sub_classes.rb +60 -0
  166. data/puppet/manifests/init.pp +72 -0
  167. data/puppet/manifests/params.pp +16 -0
  168. data/puppet/r8meta.puppet.yml +35 -0
  169. data/puppet/templates/bash_profile.erb +2 -0
  170. data/puppet/templates/client.conf.erb +1 -0
  171. data/puppet/templates/dtkclient.erb +2 -0
  172. data/spec/component_module_spec.rb +34 -0
  173. data/spec/dependency_spec.rb +6 -0
  174. data/spec/dtk_shell_spec.rb +13 -0
  175. data/spec/dtk_spec.rb +33 -0
  176. data/spec/lib/spec_helper.rb +10 -0
  177. data/spec/lib/spec_thor.rb +108 -0
  178. data/spec/node_template_spec.rb +24 -0
  179. data/spec/project_spec.rb +6 -0
  180. data/spec/repo_spec.rb +7 -0
  181. data/spec/response_spec.rb +52 -0
  182. data/spec/service_module_spec.rb +38 -0
  183. data/spec/service_spec.rb +50 -0
  184. data/spec/state_change_spec.rb +7 -0
  185. data/spec/table_print_spec.rb +48 -0
  186. data/spec/target_spec.rb +57 -0
  187. data/spec/task_spec.rb +28 -0
  188. data/views/assembly/augmented_simple_list.rb +12 -0
  189. data/views/assembly_template/augmented_simple_list.rb +12 -0
  190. data/views/list_task/augmented_simple_list.rb +12 -0
  191. metadata +421 -0
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK
19
+ module Shell
20
+ class ContextAux
21
+
22
+ class << self
23
+
24
+ def is_double_dot?(command)
25
+ return command.match(/\.\.[\/]?/)
26
+ end
27
+
28
+ # returns number of first '..' elements in array
29
+ def count_double_dots(entries)
30
+ double_dots_count = 0
31
+ # we check for '..' and remove them
32
+ entries.each do |e|
33
+ if is_double_dot?(e)
34
+ double_dots_count += 1
35
+ else
36
+ break
37
+ end
38
+ end
39
+
40
+ return double_dots_count
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,186 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Shell
19
+ class ActiveContext
20
+
21
+ # special case when we are not able to provide valid identifier but we are
22
+ # using it as such
23
+ NO_IDENTIFIER_PROVIDED = -1
24
+
25
+ # TODO: Remove accessor for debug purpose only
26
+ attr_accessor :context_list
27
+
28
+ def clone_me()
29
+ inst = ActiveContext.new
30
+ inst.context_list = @context_list.clone
31
+ return inst
32
+ end
33
+
34
+ def initialize
35
+ @context_list = []
36
+ end
37
+
38
+ def push_new_context(context_name, entity_name, context_value=nil, shadow_entity=nil)
39
+ @context_list << ContextEntity.create_context(context_name, entity_name, context_value, :id, shadow_entity)
40
+ end
41
+
42
+ def push_new_name_context(context_name, entity_name, context_value=nil)
43
+ @context_list << ContextEntity.create_context(context_name, entity_name, context_value, :name)
44
+ end
45
+
46
+ def pop_context(n)
47
+ return @context_list.pop(n)
48
+ end
49
+
50
+ def find_identifier(entity_name)
51
+ results = @context_list.select { |e| (e.is_identifier? && (e.entity == entity_name.to_sym))}
52
+ return results.first
53
+ end
54
+
55
+ def find_command(entity_name)
56
+ results = @context_list.select { |e| (e.is_command? && (e.entity == entity_name.to_sym))}
57
+ return results.first
58
+ end
59
+
60
+ def name_list()
61
+ @context_list.collect { |e| e.is_alt_identifier? ? e.transform_alt_identifier_name : e.name }
62
+ end
63
+
64
+ def name_list_simple()
65
+ @context_list.collect { |e| e.name }
66
+ end
67
+
68
+
69
+ # returns list of entities that have identifier
70
+ def commands_that_have_identifiers()
71
+ filtered_entities = @context_list.select { |e| e.is_identifier? }
72
+ return filtered_entities.collect { |e| e.entity.to_s }
73
+ end
74
+
75
+ def command_list()
76
+ filtered_entities = @context_list.select { |e| e.is_command? }
77
+ return filtered_entities.collect { |e| e.entity.to_s }
78
+ end
79
+
80
+ # returns id to be used to retrive task list form the cache based on
81
+ # current active context
82
+ def get_task_cache_id()
83
+ identifier = command_list().join('_')
84
+ return 'dtk' if identifier.empty?
85
+ if current_alt_identifier?
86
+ return "#{identifier}_#{current_alt_identifier_name()}".to_sym()
87
+ end
88
+
89
+ return current_identifier? ? "#{identifier}_wid".to_sym : identifier.to_sym
90
+ end
91
+
92
+ def full_path()
93
+ path = name_list().join('/')
94
+ path = Context.enchance_path_with_alias(path, @context_list)
95
+
96
+ return "/#{path}"
97
+ end
98
+
99
+ def clear()
100
+ @context_list.clear
101
+ end
102
+
103
+ def empty?()
104
+ return @context_list.empty?
105
+ end
106
+
107
+ def is_n_context?
108
+ @context_list.size > 2
109
+ end
110
+
111
+ def is_base_context?
112
+ @context_list.size == 1
113
+ end
114
+
115
+ def is_root_context?
116
+ @context_list.size == 0
117
+ end
118
+
119
+ def current_command?
120
+ return @context_list.empty? ? true : @context_list.last.is_command?
121
+ end
122
+
123
+ def current_identifier?
124
+ return @context_list.empty? ? false : @context_list.last.is_identifier?
125
+ end
126
+
127
+ def current_alt_identifier?
128
+ return @context_list.empty? ? false : @context_list.last.is_alt_identifier?
129
+ end
130
+
131
+ def current_alt_identifier_name
132
+ @context_list.last.alt_identifier
133
+ end
134
+
135
+ def first_command_name()
136
+ @context_list.each do |e|
137
+ return e.name if e.is_command?
138
+ end
139
+
140
+ return nil
141
+ end
142
+
143
+ def is_there_identifier_for_first_context?
144
+ @context_list.each { |e| return true if e.is_identifier? }
145
+ return false
146
+ end
147
+
148
+ def last_command_name()
149
+ @context_list.reverse.each do |e|
150
+ return e.name if e.is_command?
151
+ end
152
+
153
+ return nil
154
+ end
155
+
156
+ def last_context_entity_name()
157
+ return @context_list.empty? ? nil : @context_list.last.entity
158
+ end
159
+
160
+ def last_context_name()
161
+ return @context_list.empty? ? nil : @context_list.last.name
162
+ end
163
+
164
+ def first_context_name()
165
+ return @context_list.empty? ? nil : @context_list.first.name
166
+ end
167
+
168
+ def first_context()
169
+ return @context_list.empty? ? nil : @context_list.first
170
+ end
171
+
172
+ def last_context()
173
+ return @context_list.empty? ? nil : @context_list.last
174
+ end
175
+
176
+ def last_context_is_shadow_entity?
177
+ return false if @context_list.empty?
178
+ !!last_context().shadow_entity
179
+ end
180
+
181
+ def shadow_entity()
182
+ return if @context_list.empty?
183
+ last_context().shadow_entity
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,89 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Shell
19
+ class ContextEntity
20
+ attr_accessor :entity
21
+ attr_accessor :name
22
+ attr_accessor :identifier
23
+ attr_accessor :alt_identifier
24
+ attr_accessor :shadow_entity
25
+
26
+ SHELL_SEPARATOR = '/'
27
+
28
+ def self.create_context(context_name, entity_name, context_value=nil, type_id=:id, shadow_entity=nil)
29
+ if context_value
30
+ if :id.eql?(type_id)
31
+ return ContextEntity.create_identifier(context_name, entity_name, context_value, shadow_entity)
32
+ else
33
+ return ContextEntity.create_name_identifier(context_name, entity_name, context_value, shadow_entity)
34
+ end
35
+ else
36
+ return ContextEntity.create_command(context_name, entity_name, shadow_entity)
37
+ end
38
+ end
39
+
40
+ def is_identifier?
41
+ return !@identifier.nil?
42
+ end
43
+
44
+ def is_alt_identifier?
45
+ return !@alt_identifier.nil?
46
+ end
47
+
48
+ def is_command?
49
+ return @identifier.nil?
50
+ end
51
+
52
+ def get_identifier(type)
53
+ return (type == 'id' ? self.identifier : self.name)
54
+ end
55
+
56
+ def transform_alt_identifier_name()
57
+ @name.gsub(::DTK::Client::CommandBaseThor::ALT_IDENTIFIER_SEPARATOR, SHELL_SEPARATOR)
58
+ end
59
+
60
+ private
61
+
62
+ def self.create_command(name, entity_name, shadow_entity=nil)
63
+ instance = ContextEntity.new
64
+ instance.name = name
65
+ instance.entity = entity_name.to_sym
66
+ instance.shadow_entity = shadow_entity
67
+ return instance
68
+ end
69
+
70
+ def self.create_name_identifier(name, entity_name, value, shadow_entity=nil)
71
+ instance = self.create_command(name,entity_name)
72
+ instance.name = value
73
+ instance.identifier = value
74
+ instance.alt_identifier = value
75
+ instance.shadow_entity = shadow_entity
76
+
77
+ return instance
78
+ end
79
+
80
+ def self.create_identifier(name, entity_name, value, shadow_entity=nil)
81
+ instance = self.create_command(name,entity_name)
82
+ instance.identifier = value
83
+ alt_identifier_name = name.to_s.split(::DTK::Client::CommandBaseThor::ALT_IDENTIFIER_SEPARATOR)
84
+ instance.alt_identifier = alt_identifier_name.size > 1 ? alt_identifier_name.first : nil
85
+ instance.shadow_entity = shadow_entity
86
+ return instance
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,223 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Shell
19
+ class ContextParams
20
+
21
+ attr_accessor :current_context
22
+ attr_accessor :method_arguments
23
+ attr_accessor :pure_cli_mode
24
+
25
+ def initialize(override_method_arguments = [])
26
+ @current_context = ActiveContext.new
27
+ @method_arguments = override_method_arguments
28
+ @thor_options = Hash.new
29
+ @pure_cli_mode = false
30
+
31
+ @method_arguments
32
+ end
33
+
34
+ def add_context_to_params(context_name, entity_name, context_value = nil)
35
+ @current_context.push_new_context(context_name, stand_name(entity_name), context_value)
36
+ end
37
+
38
+ def add_context_name_to_params(context_name, entity_name, context_value = nil)
39
+ @current_context.push_new_name_context(context_name, stand_name(entity_name), context_value)
40
+ end
41
+
42
+ def forward_options(options)
43
+ @thor_options = options
44
+ end
45
+
46
+ def get_forwarded_options()
47
+ @thor_options
48
+ end
49
+
50
+ def get_forwarded_thor_option(option_key)
51
+ return @thor_options ? @thor_options[option_key] : nil
52
+ end
53
+
54
+ def override_method_argument!(key, value)
55
+ id = match_argument_id(key)
56
+ raise DTK::Client::DtkImplementationError, "Wrong identifier used '#{key}', ID not matched!" unless id
57
+ @method_arguments[id] = value
58
+ end
59
+
60
+ # can be class methods but no need, since we have this instance available in each method
61
+ def retrieve_thor_options(mapping, options)
62
+ results = []
63
+ errors = []
64
+
65
+ mapping.each do |key|
66
+ required = key.to_s.match(/.+!$/)
67
+ thor_key = key.to_s.gsub('!','')
68
+
69
+ results << element = options[thor_key]
70
+
71
+ if required && element.nil?
72
+ errors << thor_key
73
+ end
74
+ end
75
+
76
+ unless errors.empty?
77
+ raise DTK::Client::DtkValidationError.new("Missing required option#{errors.size > 1 ? 's' : ''}: #{errors.join(', ')}", true)
78
+ end
79
+
80
+ return ((results.size == 1) ? results.first : results)
81
+ end
82
+
83
+ def retrieve_arguments(mapping, method_info = [])
84
+ results = []
85
+ errors = []
86
+
87
+ # using context_name when have array as key_mapping [:assembly_id, :workspace_id]
88
+ # to determine which context is used
89
+ context_name = method_info.first.split('-').first unless method_info.empty?
90
+
91
+ mapping.each do |key_mapping|
92
+
93
+ is_array = key_mapping.is_a?(Array)
94
+
95
+ selected_key = is_array ? key_mapping.first : key_mapping
96
+
97
+ required = selected_key.to_s.match(/.+!$/)
98
+
99
+ element = nil
100
+ matched = selected_key.to_s.match(/option_([0-9]+)/)
101
+ if matched
102
+ id = matched[1].to_i - 1
103
+ element = @method_arguments[id].dup if @method_arguments[id]
104
+
105
+ # used if last parameter has more than one word
106
+ # e.g. set-attribute attr_name "some value" (thor separates 'some value' as two parameters but we need it as one)
107
+ if(mapping.last.to_s.eql?(key_mapping.to_s))
108
+ new_id = id+1
109
+ while @method_arguments[new_id] do
110
+ element << " #{@method_arguments[new_id]}"
111
+ new_id += 1;
112
+ end
113
+ end
114
+
115
+ unless method_info.empty?
116
+ unless element
117
+ errors << method_info[id] if required
118
+ end
119
+ end
120
+
121
+ else
122
+ # More complex split regex for extracting entitiy name from mapping due to complex context names
123
+ # i.e. assembly-template will have assembly_template_id mapping
124
+ element = check_context_for_element(selected_key)
125
+
126
+ # if we are dealing with array we need to check rest of the keys since it is OR
127
+ # approach if first element not found take second
128
+ if element.nil? && is_array
129
+ key_mapping[1..-1].each do |alternative_key|
130
+ element = check_context_for_element(alternative_key)
131
+ break if element
132
+ if context_name
133
+ if alternative_key.to_s.include?(context_name.downcase)
134
+ required = alternative_key.to_s.match(/.+!$/)
135
+ selected_key = alternative_key
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ unless element
142
+ errors << "#{entity_name(selected_key).upcase} ID/NAME" if required
143
+ end
144
+ end
145
+
146
+ results << element
147
+ end
148
+
149
+ unless errors.empty?
150
+ raise DTK::Client::DtkValidationError.new("Missing required argument#{errors.size > 1 ? 's' : ''}: #{errors.join(', ')}", true)
151
+ end
152
+
153
+ return ((results.size == 1) ? results.first : results)
154
+ end
155
+
156
+ def is_last_command_eql_to?(command_name)
157
+ return @current_context.last_command_name() == command_name.to_s
158
+ end
159
+
160
+ def is_there_identifier?(entity_name)
161
+ return @current_context.find_identifier(entity_name) != nil
162
+ end
163
+
164
+ def is_there_command?(entity_name)
165
+ return @current_context.find_command(entity_name) != nil
166
+ end
167
+ def current_command?
168
+ return @current_context.current_command?
169
+ end
170
+ def root_command_name
171
+ @current_context.first_command_name
172
+ end
173
+ def last_entity_name
174
+ @current_context.last_context_entity_name
175
+ end
176
+ def shadow_entity_name()
177
+ @current_context.shadow_entity()
178
+ end
179
+
180
+ private
181
+
182
+ # matches argument id (integer) from used identifier (symbol)
183
+ #
184
+ # Returns: Integer as ID , or nil if not found
185
+ def match_argument_id(identifier)
186
+ matched = identifier.to_s.match(/option_([0-9]+)/)
187
+ (matched ? matched[1].to_i - 1 : nil)
188
+ end
189
+
190
+ # based on map key binding e.g. assembly_id, assembly_name we will extrace value
191
+ # from our ActiveContext
192
+ def check_context_for_element(key_mapping)
193
+ split_info = split_info(key_mapping)
194
+ entity_name = entity_name(key_mapping,split_info)
195
+ id_type = split_info[1].gsub(/!/,'') # for required elements we remove '!' required marker
196
+ context_identifier = @current_context.find_identifier(entity_name)
197
+ if context_identifier
198
+ return context_identifier.get_identifier(id_type)
199
+ else
200
+ return nil
201
+ end
202
+ end
203
+
204
+ def entity_name(key_mapping,split_info=nil)
205
+ split_info ||= split_info(key_mapping)
206
+ split_info[0].gsub(/_/,'-') # makes sure we are using entity names with '_'
207
+ end
208
+
209
+ #
210
+ # Standardize context name since we are in domain treating :component_module as :'component-module'
211
+ # and need to be careful about these changes
212
+ #
213
+
214
+ def stand_name(name)
215
+ name.to_s.gsub('_','-').to_sym
216
+ end
217
+
218
+ def split_info(key_mapping)
219
+ key_mapping.to_s.split(/_([a-z]+!?$)/)
220
+ end
221
+
222
+ end
223
+ end