dtk-shell 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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,88 @@
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
+
21
+ class CachedTasks < Hash
22
+ end
23
+
24
+ class OverrideTasks < Hash
25
+
26
+ attr_accessor :completed_tasks
27
+ attr_accessor :always_load_list
28
+
29
+
30
+ # help_item (Thor printable task), structure:
31
+ # [0] => task defintion
32
+ # [1] => task description
33
+ # [2] => task name
34
+
35
+ # overriden_task (DTK override task), structure:
36
+ # [0] => task name
37
+ # [1] => task defintion
38
+ # [2] => task description
39
+
40
+ # using 'always load listed' to skip adding task to completed tasks e.g load utils for workspace and workspace_node
41
+ def initialize(hash=nil, always_load_listed=[])
42
+ super(hash)
43
+ @completed_tasks = []
44
+ @always_load_list = always_load_listed
45
+ self.merge!(hash)
46
+ end
47
+
48
+ # returns true if there are overrides for tasks on first two levels.
49
+ def are_there_self_override_tasks?
50
+ return (self[:all][:self] || self[:command_only][:self] || self[:identifier_only][:self])
51
+ end
52
+
53
+ def check_help_item(help_item, is_command)
54
+ command_tasks, identifier_tasks = get_all_tasks(:self)
55
+ found = []
56
+
57
+ if is_command
58
+ found = command_tasks.select { |o_task| o_task[0].eql?(help_item[2]) }
59
+ else
60
+ found = identifier_tasks.select { |o_task| o_task[0].eql?(help_item[2]) }
61
+ end
62
+
63
+ # if we find self overriden task we remove it
64
+ # [found.first[1],found.first[2],found.first[0]] => we convert from o_task structure to thor help structure
65
+ return found.empty? ? help_item : [found.first[1],found.first[2],found.first[0]]
66
+ end
67
+
68
+ # returns 2 arrays one for commands and next one for identifiers
69
+ def get_all_tasks(child_name)
70
+ command_o_tasks, identifier_o_tasks = [], []
71
+ command_o_tasks = (self[:all][child_name]||[]) + (self[:command_only][child_name]||[])
72
+ identifier_o_tasks = (self[:all][child_name]||[]) + (self[:identifier_only][child_name]||[])
73
+ return command_o_tasks, identifier_o_tasks
74
+ end
75
+
76
+ def is_completed?(child_name)
77
+ # do not add task to completed if explicitly said to always load that task
78
+ return false if @always_load_list.include?(child_name)
79
+ @completed_tasks.include?(child_name)
80
+ end
81
+
82
+ def add_to_completed(child_name)
83
+ @completed_tasks << child_name
84
+ end
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,76 @@
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
+ ##
19
+ # This is temporary workaround to faciliate concept we are introducing
20
+ #
21
+ # Entity / Double Entity Identifier
22
+ #
23
+
24
+ module DTK
25
+ module Shell
26
+ class ShadowEntity
27
+
28
+ def self.resolve(context_entity)
29
+ entity, shadow_entity = context_entity.entity, context_entity.shadow_entity
30
+
31
+ return nil if shadow_entity.nil? || entity.nil?
32
+ entity_mapping = @shadow_mapping.fetch(entity.to_sym)
33
+
34
+ return entity_mapping ? entity_mapping.fetch(shadow_entity.to_sym) : nil
35
+ end
36
+
37
+ def self.resolve_tasks(context_entity)
38
+ entity, shadow_entity = context_entity.entity, context_entity.shadow_entity
39
+ entity_mapping = @shadow_mapping.fetch(entity.to_sym)
40
+
41
+ raise DTK::Client::DtkError, "You are missing mapping for shadow entity #{entity} / #{shadow_entity} you need to specify it" if entity_mapping.nil?
42
+
43
+ shadow_entity_mapping = entity_mapping.fetch(shadow_entity.to_sym)
44
+
45
+ # return just task names
46
+ return shadow_entity_mapping.collect { |se_map| se_map.first.split(' ').first }
47
+ end
48
+
49
+ private
50
+
51
+ @shadow_mapping = {
52
+ :node => {
53
+ :node_group => [
54
+ ["add-component COMPONENT", "# Add a component to the node."],
55
+ ["list-attributes", "# List attributes associated with service's node."],
56
+ ["list-components", "# List components associated with service's node."],
57
+ ["delete-component COMPONENT-NAME [-y]", "# Delete component from service's node"],
58
+ ["set-attribute ATTRIBUTE-NAME [VALUE] [-u]", "# (Un)Set attribute value. The option -u will unset the attribute's value."]
59
+ ],
60
+ :node_group_node => [
61
+ ["info", "# Return info about node instance belonging to given workspace."],
62
+ ["start", "# Start node instance."],
63
+ ["stop", "# Stop node instance."],
64
+ ["ssh REMOTE-USER [-i PATH-TO-PEM]", "# SSH into node, optional parameters are path to identity file."]
65
+ ]
66
+ }
67
+ }
68
+
69
+ if ::DTK::Configuration.get(:development_mode)
70
+ @shadow_mapping[:node][:node_group_node] << ["test-action-agent BASH-COMMAND-LINE", "# Run bash command on test action agent"]
71
+ end
72
+
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,44 @@
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
+ require 'hirb'
19
+
20
+ module DTK
21
+ module Shell
22
+
23
+ # We will use this class to generate header for console which would be always present,
24
+ # when activated. Hirb implementation will be used to display status information.
25
+
26
+ class HeaderShell
27
+
28
+ attr_accessor :active
29
+ alias_method :is_active?, :active
30
+
31
+ def initialize
32
+ @active = true
33
+ end
34
+
35
+ def print_header
36
+ puts "*********************"
37
+ puts "********************* #{Time.now} "
38
+ puts "*********************"
39
+ end
40
+
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,283 @@
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
+ class Thor
19
+ class << self
20
+ # NOTE: Class is loaded automaticly in dtk-shell
21
+
22
+ @@shell_context = nil
23
+ HIDE_FROM_BASE_CONTEXT_HELP = "HIDE_FROM_BASE"
24
+
25
+ def set_context(context)
26
+ @@shell_context = context
27
+ end
28
+
29
+ def match_help_item_changes(help_item, entity_name)
30
+ help_item.first.match(/^\[?#{entity_name.upcase}.?(NAME\/ID|ID\/NAME|ID|NAME)(\-?PATTERN)?\]?/)
31
+ end
32
+
33
+ def replace_if_matched!(help_item, matched)
34
+ # change by reference
35
+ help_item.first.gsub!(matched[0],'') if matched
36
+
37
+ return help_item
38
+ end
39
+
40
+ # Method returns alternative providers
41
+ def get_alternative_identifiers(command_name)
42
+ # we check for alternate identifiers
43
+ command_clazz = ::DTK::Client::OsUtil.get_dtk_class(command_name)
44
+
45
+ if (command_clazz && command_clazz.respond_to?(:alternate_identifiers))
46
+ return command_clazz.alternate_identifiers()
47
+ end
48
+
49
+ return []
50
+ end
51
+
52
+ # Monkey path of printable task methods to include name as well
53
+ # Returns tasks ready to be printed.
54
+ def printable_tasks(all = true, subcommand = false)
55
+ (all ? all_tasks : tasks).map do |_, task|
56
+ # using HIDE_FROM_BASE to hide command from base context help (e.g from dtk:/assembly>help) ...
57
+ # but show that command in other context help (e.g in dtk:/assembly/assembly_id/utils>help)
58
+ # added (task.name.eql?('help')) to hide help from command list
59
+ next if (task.hidden? || (task.name.eql?("help")) || (task.usage.include?(HIDE_FROM_BASE_CONTEXT_HELP) && (@@shell_context ? !@@shell_context.active_context.is_n_context? : '')))
60
+ item = []
61
+ item << banner(task, false, subcommand)
62
+ item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
63
+ item << task.name
64
+ item
65
+ end.compact
66
+ end
67
+
68
+ # method will check if help is overriden and if so it will replace help description,
69
+ # with overriden one, override_tasks => class => OverrideTasks
70
+ def overriden_help(override_tasks, help_item, is_command)
71
+ return (override_tasks && override_tasks.are_there_self_override_tasks?) ? override_tasks.check_help_item(help_item, is_command) : help_item
72
+ end
73
+
74
+ def help(shell, subcommand = false)
75
+ list = printable_tasks(true, subcommand)
76
+
77
+ Thor::Util.thor_classes_in(self).each do |klass|
78
+ list += klass.printable_tasks(false)
79
+ end
80
+
81
+ list.sort!{ |a,b| a[0] <=> b[0] }
82
+
83
+ # monkey patching here => START
84
+ if @@shell_context
85
+ unless @@shell_context.root?
86
+
87
+ active_context = @@shell_context.active_context
88
+
89
+ # first command we are using:
90
+ # e.g. dtk:\assembly\assembly1\node\node123> => command would be :assembly
91
+ command = active_context.first_command_name.upcase
92
+
93
+ # is there identifier for given commands (first)
94
+ # e.g. dtk:\assembly\assembly1\node\node123> => identifier here would be 'assembly1'
95
+ is_there_identifier = active_context.is_there_identifier_for_first_context?
96
+
97
+ # alternative providers
98
+ alt_identifiers = get_alternative_identifiers(command)
99
+
100
+
101
+ filtered_list = []
102
+
103
+ # case when we are not on first level and it is not identifier we skip help
104
+ # since it needs to be empty
105
+ # e.g. assembly/bootstrap1/node> ... HELP IS EMPTY FOR THIS
106
+
107
+
108
+ # override objects are special cases defined in Thor classes
109
+ # base on level there will be included in help context, help content is calculated by:
110
+ #
111
+ # 1) Matching help items with Regex (see bellow)
112
+ # 2) Adding help items from override_methods
113
+ #
114
+ #
115
+ override_tasks_obj = self.respond_to?(:override_allowed_methods) ? self.override_allowed_methods.dup : nil
116
+
117
+ shadow_list = ::DTK::Shell::ShadowEntity.resolve(active_context.last_context)
118
+ # N-LEVEL-CONTEXT - context that has at least 2 commands and 1 or more identifiers
119
+ # e.g. dtk:\assembly\assembly1\node> THIS IS N-LEVEL CONTEXT
120
+ # e.g. dtk:\assembly\assembly1\node\node123> THIS IS N-LEVEL CONTEXT
121
+ # e.g. dtk:\assembly\assembly1> THIS IS NOT N-LEVEL CONTEXT
122
+ #
123
+ unless shadow_list
124
+ if (!active_context.is_n_context? || active_context.current_identifier?)
125
+
126
+ list.each do |help_item|
127
+ help_item.first.gsub!("^^", '') if help_item.first.include?("^^")
128
+
129
+ # this will match entity_name (command) and alternative identifiers
130
+ identifers = [command] + alt_identifiers
131
+
132
+ # matches identifiers for ID/NAME
133
+ matched_data = help_item.first.match(/^\s\[?(#{identifers.join('|')}).?(NAME\/ID|ID\/NAME)\]?\s/)
134
+ alt_matched_data = help_item.first.match(/^\s\[?(#{alt_identifiers.join('|')}).?(NAME\/ID|ID\/NAME)\]?\s/)
135
+
136
+ if matched_data.nil?
137
+ # not found and tier 1 we add it to help list
138
+ filtered_list << overriden_help(override_tasks_obj, help_item, true) if @@shell_context.current_command?
139
+ else
140
+ # for help we only care about first context name / identifier
141
+ if !is_there_identifier
142
+ # if it contains [] it is optional and will be available on both tiers
143
+ if matched_data[0].include?('[')
144
+ # we remove it, since there is no need to use it
145
+ help_item.first.gsub!(matched_data[0],' ') unless help_item.nil?
146
+ filtered_list << overriden_help(override_tasks_obj, help_item, true)
147
+ end
148
+ else
149
+ # Adding alt identifiers here
150
+ if alt_matched_data
151
+ if active_context.current_alt_identifier?
152
+ help_item.first.gsub!(matched_data[0],'') unless help_item.nil?
153
+ filtered_list << overriden_help(override_tasks_obj, help_item, false)
154
+ end
155
+ else
156
+ unless active_context.current_alt_identifier?
157
+ help_item.first.gsub!(matched_data[0],'') unless help_item.nil?
158
+ filtered_list << overriden_help(override_tasks_obj, help_item, false)
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ # This will return commands that have identifiers
167
+ # e.g. dtk:\assembly\assembly1\node\node123> => ['assembly','node']
168
+ commands_that_have_identifiers = active_context.commands_that_have_identifiers()
169
+ is_n_level_context = active_context.command_list.size > 1
170
+
171
+ # first one does not count
172
+ if is_n_level_context
173
+ # additional filter list for n-context
174
+ n_filter_list = []
175
+ # we do not need first one, since above code takes care of that one
176
+ filtered_list = filtered_list.select do |filtered_help_item|
177
+ #next unless filtered_help_item
178
+ unless commands_that_have_identifiers.empty?
179
+ commands_that_have_identifiers[1..-1].each_with_index do |entity,i|
180
+ matched = match_help_item_changes(filtered_help_item, entity)
181
+ filtered_help_item = replace_if_matched!(filtered_help_item, matched)
182
+
183
+ # if it is last command, and there were changes
184
+ if (i == (commands_that_have_identifiers.size - 2) && matched)
185
+ n_filter_list << filtered_help_item
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ if override_tasks_obj && is_n_level_context
192
+ last_entity_name = active_context.last_context_entity_name.to_sym
193
+
194
+ # special case for node_id/utils (we don't want to use utils from service context)
195
+ command_list = active_context.command_list
196
+ if (command_list.size > 2) && command_list.last.eql?('utils')
197
+ last_entity_name = command_list.last(2).join('_').to_sym
198
+ end
199
+
200
+ # we get commands task, and identifier tasks for given entity (e.g. :assembly)
201
+ command_o_tasks, identifier_o_tasks = override_tasks_obj.get_all_tasks(last_entity_name)
202
+
203
+ if active_context.current_identifier?
204
+ identifier_o_tasks.each do |o_task|
205
+ n_filter_list << [o_task[1],o_task[2]]
206
+ end
207
+ else
208
+ command_o_tasks.each do |o_task|
209
+ n_filter_list << [o_task[1],o_task[2]]
210
+ end
211
+ end
212
+ end
213
+
214
+ # we have just filtered those methods that have attribute for given entity
215
+ # and also are last in the list
216
+ filtered_list = n_filter_list
217
+ end
218
+
219
+ # remove double spaces
220
+ list = filtered_list.each { |e| e.first.gsub!(/ /,' ') }
221
+ else
222
+ list = shadow_list
223
+ end
224
+ end
225
+ else
226
+ # no dtk-shell just dtk, we make sure that underscore is not used '_'
227
+ list = list.collect do |item|
228
+
229
+ #
230
+ # e.g.
231
+ # dtk assembly_template info
232
+ # dtk assembly-template info
233
+ #
234
+ item[0] = item[0].gsub(/^dtk ([a-zA-Z]+)_([a-zA-Z]+) /,'dtk \1-\2 ')
235
+ item
236
+ end
237
+ end
238
+
239
+ if list.empty?
240
+ shell.say ""
241
+ shell.say "No tasks for current context '#{@@shell_context.active_context.full_path}'."
242
+ end
243
+
244
+ # remove helper 3. element in help item list
245
+ list = list.collect { |e| e[0..1] }
246
+
247
+ # monkey patching here => END
248
+ shell.print_table(list, :indent => 2, :truncate => true)
249
+ shell.say
250
+
251
+
252
+ # print sub context information
253
+ sub_children = []
254
+
255
+ # current active context clazz
256
+ if @@shell_context
257
+ last_command_name = @@shell_context.active_context.last_command_name
258
+ command_clazz = DTK::Shell::Context.get_command_class(last_command_name)
259
+
260
+ if @@shell_context && @@shell_context.active_context.current_identifier?
261
+ sub_children += command_clazz.valid_children() if command_clazz.respond_to?(:valid_children)
262
+ sub_children += command_clazz.invisible_context_list()
263
+ # remove utils subcontext from help in service/service_name/node_group only
264
+ if @@shell_context.active_context.last_context_is_shadow_entity? && @@shell_context.active_context.shadow_entity().eql?('node_group')
265
+ sub_children.delete(:utils)
266
+ end
267
+ else
268
+ if command_clazz.respond_to?(:validation_list)
269
+ sub_children += ["#{last_command_name}-identifier"]
270
+ end
271
+ end
272
+
273
+ unless sub_children.empty?
274
+ shell.say(" Change context (cc) to: #{sub_children.join(', ')}", :BOLD)
275
+ shell.say
276
+ end
277
+ end
278
+
279
+
280
+ class_options_help(shell)
281
+ end
282
+ end
283
+ end