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,40 @@
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; module Client
19
+ class CommandBaseThor
20
+ module CommonOptionDefs
21
+ module Mixin
22
+ def required_option(key)
23
+ key = key.to_s
24
+ unless options.has_key?(key)
25
+ raise DtkError, "[ERROR] The mandatory option --#{key} is missing"
26
+ end
27
+ options[key]
28
+ end
29
+ end
30
+ module ClassMixin
31
+ def version_method_option()
32
+ method_option "version",:aliases => "-v",
33
+ :type => :string,
34
+ :banner => "VERSION",
35
+ :desc => "Version"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end; end
@@ -0,0 +1,104 @@
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 File.expand_path('../lib/error', File.dirname(__FILE__))
19
+
20
+ # we leave possibilites that folders user multiple names
21
+ # when somebody takes fresh projects from git it is expected that
22
+ # person will use dtk-common name
23
+ POSSIBLE_COMMON_CORE_FOLDERS = ['dtk-common-repo','dtk-common-core']
24
+
25
+
26
+ def dtk_require(*files_x)
27
+ files = (files_x.first.kind_of?(Array) ? files_x.first : files_x)
28
+ caller_dir = caller.first.gsub(/\/[^\/]+$/,"")
29
+ files.each{|f|require File.expand_path(f,caller_dir)}
30
+ end
31
+
32
+ def dtk_require_from_base(*files_x)
33
+ #different than just calling dtk_require because of change to context give by caller
34
+ dtk_require(*files_x)
35
+ end
36
+
37
+ def dtk_require_common_commands(*files_x)
38
+ dtk_require_from_base(*files_x.map{|f|"commands/common/#{f}"})
39
+ end
40
+
41
+ def dtk_nested_require(dir,*files_x)
42
+ files = (files_x.first.kind_of?(Array) ? files_x.first : files_x)
43
+ caller_dir = caller.first.gsub(/\/[^\/]+$/,"")
44
+
45
+ # invalid command will be send here as such needs to be handled.
46
+ # we will throw DtkClient error as invalid command
47
+ files.each do |f|
48
+ begin
49
+ require File.expand_path("#{dir}/#{f}",caller_dir)
50
+ rescue LoadError => e
51
+ if e.message.include? "#{dir}/#{f}"
52
+ raise DTK::Client::DtkError,"Command '#{f}' not found."
53
+ else
54
+ raise e
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ # this returns true if there is no common folder e.g. dtk-common in parent folder,
61
+ # and gem is installed
62
+ def gem_only_available?()
63
+ return !determine_common_folder() && is_dtk_common_core_gem_installed?
64
+ end
65
+
66
+ def dtk_require_dtk_common_core(common_library)
67
+ # use common folder else common gem
68
+ common_folder = determine_common_folder()
69
+
70
+ if common_folder
71
+ dtk_require("../../" + common_folder + "/lib/#{common_library}")
72
+ elsif is_dtk_common_core_gem_installed?
73
+ # already loaded so do not do anything
74
+ else
75
+ raise DTK::Client::DtkError,"Common directory/gem not found, please make sure that you have cloned dtk-common folder or installed dtk common gem!"
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ ##
82
+ # Check if dtk-common gem has been installed if so use common gem. If there is no gem
83
+ # logic from dtk_require_dtk_common will try to find commond folder.
84
+ # DEVELOPER NOTE: Uninstall dtk-common gem when changing dtk-common to avoid re-building gem.
85
+ def is_dtk_common_core_gem_installed?
86
+ begin
87
+ # if no exception gem is found
88
+ gem 'dtk-common-core'
89
+ return true
90
+ rescue Gem::LoadError
91
+ return false
92
+ end
93
+ end
94
+
95
+ ##
96
+ # Checks for expected names of dtk-common folder and returns name of existing common folder
97
+ def determine_common_folder
98
+ POSSIBLE_COMMON_CORE_FOLDERS.each do |folder|
99
+ path = File.join(File.dirname(__FILE__),'..','..',folder)
100
+ return folder if File.directory?(path)
101
+ end
102
+
103
+ return nil
104
+ 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
+ module DTK
19
+ module Client
20
+ class SearchHash < Hash
21
+ def cols=(cols)
22
+ self.merge!(:columns => cols)
23
+ end
24
+ def filter=(filter)
25
+ self.merge!(:filter => filter)
26
+ end
27
+ def set_order_by!(col,dir="ASC")
28
+ unless %w{ASC DESC}.include?(dir)
29
+ raise Error.new("set order by direction must by 'ASC' or 'DESC'")
30
+ end
31
+ order_by =
32
+ [{
33
+ :field => col,
34
+ :order => dir
35
+ }]
36
+ self.merge!(:order_by => order_by)
37
+ end
38
+
39
+ def post_body_hash()
40
+ {:search => JSON.generate(self)}
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,261 @@
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 File.expand_path('client', File.dirname(__FILE__))
19
+ require File.expand_path('parser/adapters/thor', File.dirname(__FILE__))
20
+ require File.expand_path('commands/thor/dtk', File.dirname(__FILE__))
21
+ require File.expand_path('error', File.dirname(__FILE__))
22
+
23
+ # load all from shell directory since those are required
24
+ Dir[File.expand_path('shell/**/*.rb', File.dirname(__FILE__))].each { |file| require file }
25
+
26
+ require 'shellwords'
27
+ require 'readline'
28
+ require 'colorize'
29
+ require 'thor'
30
+
31
+ # ideas from http://bogojoker.com/readline/#trap_sigint_and_restore_the_state_of_the_terminal
32
+
33
+ # GLOBAL IDENTIFIER
34
+ $shell_mode = true
35
+
36
+ ALIAS_COMMANDS = {
37
+ 'ls' => 'list',
38
+ 'cd' => 'cc',
39
+ 'rm' => 'delete'
40
+ }
41
+
42
+ class MainContext
43
+ include Singleton
44
+
45
+ attr_accessor :context
46
+
47
+ def initialize
48
+ @context = DTK::Shell::Context.new
49
+ end
50
+
51
+ def self.get_context
52
+ MainContext.instance.context
53
+ end
54
+ end
55
+
56
+ # METHODS
57
+
58
+ # support for alias commands (ls for list, cd for cc etc.)
59
+ def preprocess_commands(original_command)
60
+ command = ALIAS_COMMANDS[original_command]
61
+ # return command if alias for specific command exist in predefined ALIAS_COMMANDS
62
+ # else return entered command because there is no alias for it
63
+ return (command.nil? ? original_command : command)
64
+ end
65
+ # RUNTIME PART - STARTS HERE
66
+
67
+ def run_shell_command()
68
+ # init shell client
69
+ init_shell_context()
70
+
71
+ # prompt init
72
+ prompt = DTK::Shell::Context::DTK_ROOT_PROMPT
73
+
74
+ # trap CTRL-C and remove current text without leaving the dtk-shell
75
+ trap("INT"){
76
+ puts "\n"
77
+ raise Interrupt
78
+ }
79
+
80
+ # runtime part
81
+ begin
82
+ while line = Readline.readline(prompt, true)
83
+ prompt = execute_shell_command(line, prompt) unless line.strip.empty?
84
+ end
85
+ rescue DTK::Shell::ExitSignal => e
86
+ # do nothing
87
+ rescue ArgumentError => e
88
+ puts e.backtrace if ::DTK::Configuration.get(:development_mode)
89
+ retry
90
+ rescue Interrupt => e
91
+ retry
92
+ rescue Exception => e
93
+ client_internal_error = DTK::Client::DtkError::Client.label()
94
+ DtkLogger.instance.error_pp("[#{client_internal_error}] #{e.message}", e.backtrace)
95
+ ensure
96
+ puts "\n" unless e.is_a? DTK::Shell::ExitSignal
97
+ # logout
98
+ DTK::Client::Session.logout()
99
+ # save users history
100
+ DTK::Shell::Context.save_session_history(Readline::HISTORY.to_a)
101
+ exit!
102
+ end
103
+ end
104
+
105
+ def init_shell_context()
106
+ begin
107
+ # @context = DTK::Shell::Context.new
108
+ @shell_header = DTK::Shell::HeaderShell.new
109
+
110
+ # loads root context
111
+ MainContext.get_context.load_context()
112
+
113
+ @t1 = nil
114
+ Readline.completion_append_character=''
115
+ DTK::Shell::Context.load_session_history().each do |c|
116
+ Readline::HISTORY.push(c)
117
+ end
118
+
119
+ rescue DTK::Client::DtkError => e
120
+ DtkLogger.instance.error(e.message, true)
121
+ puts "Exiting ..."
122
+ raise DTK::Shell::ExitSignal
123
+ end
124
+ end
125
+
126
+ def execute_shell_command(line, prompt)
127
+ begin
128
+ # remove single/double quotes from string because shellwords module is not able to parse it
129
+ if matched = line.scan(/['"]/)
130
+ line.gsub!(/['"]/, '') if matched.size.odd?
131
+ end
132
+
133
+ # some special cases
134
+ raise DTK::Shell::ExitSignal if line == 'exit'
135
+ return prompt if line.empty?
136
+ if line == 'clear'
137
+ DTK::Client::OsUtil::clear_screen
138
+ return prompt
139
+ end
140
+ # when using help on root this is needed
141
+ line = 'dtk help' if (line == 'help' && MainContext.get_context.root?)
142
+
143
+ args = Shellwords.split(line)
144
+ cmd = args.shift
145
+
146
+ # support command alias (ls for list etc.)
147
+ cmd = preprocess_commands(cmd)
148
+
149
+ # DEV only reload shell
150
+ if ::DTK::Configuration.get(:development_mode)
151
+ if ('restart' == cmd)
152
+ puts "DEV Reloading shell ..."
153
+ ::DTK::Client::OsUtil.dev_reload_shell()
154
+ return prompt
155
+ end
156
+ end
157
+
158
+
159
+ if ('cc' == cmd)
160
+ # in case there is no params we just reload command
161
+ args << "/" if args.empty?
162
+ prompt = MainContext.get_context.change_context(args, cmd)
163
+ elsif ('popc' == cmd)
164
+ MainContext.get_context.dirs.shift()
165
+ args << (MainContext.get_context.dirs.first.nil? ? '/' : MainContext.get_context.dirs.first)
166
+ prompt = MainContext.get_context.change_context(args, cmd)
167
+ elsif ('pushc' == cmd)
168
+ if args.empty?
169
+ args << (MainContext.get_context.dirs[1].nil? ? '/' : MainContext.get_context.dirs[1])
170
+ MainContext.get_context.dirs.unshift(args.first)
171
+ MainContext.get_context.dirs.uniq!
172
+ prompt = MainContext.get_context.change_context(args, cmd)
173
+ else
174
+ prompt = MainContext.get_context.change_context(args)
175
+ # using regex to remove dtk: and > from path returned by change_context
176
+ # e.g transform dtk:/assembly/node> to /assembly/node
177
+ full_path = prompt.match(/[dtk:](\/.*)[>]/)[1]
178
+ MainContext.get_context.dirs.unshift(full_path)
179
+ end
180
+ elsif ('dirs' == cmd)
181
+ puts MainContext.get_context.dirs.inspect
182
+ else
183
+
184
+ # get all next-context-candidates (e.g. for assembly get all assembly_names)
185
+ context_candidates = MainContext.get_context.get_ac_candidates_for_context(MainContext.get_context.active_context.last_context(), MainContext.get_context.active_context())
186
+
187
+ # this part of the code is used for calling of nested commands from base context (dtk:/>assembly/assembly_id converge)
188
+ # base_command is used to check if first command from n-level is valid e.g.
189
+ # (dtk:/>assembly/assembly_id converge - chech if 'assembly' exists in context_candidates)
190
+ # revert_context is used to return to context which command is called from after command is executed
191
+ base_command = cmd.split('/').first
192
+ revert_context = false
193
+
194
+ if context_candidates.include?(base_command)
195
+ MainContext.get_context.change_context([cmd])
196
+ cmd = args.shift
197
+ revert_context = true
198
+ end
199
+
200
+ if cmd.nil?
201
+ prompt = MainContext.get_context.change_context(["-"]) if revert_context
202
+ raise DTK::Client::DtkValidationError, "You have to provide command after context name. Usage: CONTEXT-TYPE/CONTEXT-NAME COMMAND [ARG1] .. [ARG2]."
203
+ end
204
+
205
+ # send monkey patch class information about context
206
+ Thor.set_context(MainContext.get_context)
207
+
208
+ # we get command and hash params, will return Validation error if command is not valid
209
+ entity_name, method_name, context_params, thor_options, invalid_options = MainContext.get_context.get_command_parameters(cmd,args)
210
+
211
+ # check if command is executed from parent context (e.g assembly_name list-nodes)
212
+ if context_candidates.include?(method_name)
213
+ context_params.add_context_to_params(method_name, entity_name, method_name)
214
+ method_name = context_params.method_arguments.shift if context_params.method_arguments.size > 0
215
+ else
216
+ unless MainContext.get_context.method_valid?(method_name)
217
+ prompt = MainContext.get_context.change_context(["-"]) if revert_context
218
+ raise DTK::Client::DtkValidationError, "Method '#{method_name}' is not valid in current context."
219
+ end
220
+ end
221
+
222
+ # raise validation error if option is not valid
223
+ raise DTK::Client::DtkValidationError.new("Option '#{invalid_options.first||method_name}' is not valid for current command!", true) unless invalid_options.empty?
224
+
225
+ # execute command via Thor
226
+ current_contex_path = MainContext.get_context.active_context.full_path
227
+ top_level_execute(entity_name, method_name, context_params, thor_options, true)
228
+
229
+ # when 'delete' or 'delete-and-destroy' command is executed reload cached tasks with latest commands
230
+ unless (args.nil? || args.empty?)
231
+ MainContext.get_context.reload_cached_tasks(entity_name) if (method_name.include?('delete') || method_name.include?('import'))
232
+ end
233
+
234
+ # check execution status, prints status to sttout
235
+ DTK::Shell::StatusMonitor.check_status()
236
+
237
+ # if we change context while executing command, change prompt as well
238
+ unless current_contex_path.eql?(MainContext.get_context.active_context.full_path)
239
+ prompt = "dtk:#{MainContext.get_context.active_context.full_path}>"
240
+ end
241
+
242
+ # after nested command called from base context is executed successfully, return to context which command is executed from
243
+ # this is the same as 'cd -' command is executed
244
+ prompt = MainContext.get_context.change_context(["-"]) if revert_context
245
+ end
246
+ rescue DTK::Client::DSLParsing => e
247
+ DTK::Client::OsUtil.print(e.message, :red)
248
+ rescue DTK::Client::DtkValidationError => e
249
+ DTK::Client::OsUtil.print(e.message, :yellow)
250
+ rescue DTK::Shell::Error => e
251
+ DtkLogger.instance.error(e.message, true)
252
+ end
253
+
254
+ return prompt
255
+ end
256
+
257
+ public
258
+
259
+ def execute_shell_command_internal(line)
260
+ execute_shell_command(line, DTK::Shell::Context::DTK_ROOT_PROMPT)
261
+ end