bcome 0.7.0 → 1.0.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 (173) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bcome +8 -39
  3. data/lib/bcome.rb +12 -3
  4. data/lib/objects/bcome/version.rb +3 -0
  5. data/lib/objects/bootup.rb +81 -0
  6. data/lib/objects/command/local.rb +40 -0
  7. data/lib/objects/config_factory.rb +36 -0
  8. data/lib/objects/driver/base.rb +30 -0
  9. data/lib/objects/driver/bucket.rb +20 -0
  10. data/lib/objects/driver/ec2.rb +44 -0
  11. data/lib/objects/driver/static.rb +4 -0
  12. data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +7 -0
  13. data/lib/objects/exception/base.rb +15 -0
  14. data/lib/objects/exception/can_only_subselect_on_inventory.rb +7 -0
  15. data/lib/objects/exception/cannot_find_internal_registry_klass.rb +7 -0
  16. data/lib/objects/exception/cannot_find_subselection_parent.rb +7 -0
  17. data/lib/objects/exception/cant_find_key_in_cloud_tags.rb +7 -0
  18. data/lib/objects/exception/cant_find_key_in_metadata.rb +7 -0
  19. data/lib/objects/exception/cant_find_proxy_host_by_identifier.rb +7 -0
  20. data/lib/objects/exception/cant_find_proxy_host_by_namespace.rb +7 -0
  21. data/lib/objects/exception/could_not_initiate_ssh_connection.rb +7 -0
  22. data/lib/objects/exception/could_not_initiate_ssh_connection_through_backend_proxy.rb +7 -0
  23. data/lib/objects/exception/deprecation_warning.rb +11 -0
  24. data/lib/objects/exception/duplicate_command_line_argument_key.rb +7 -0
  25. data/lib/objects/exception/ec2_driver_missing_provisioning_region.rb +7 -0
  26. data/lib/objects/exception/failed_to_run_local_command.rb +7 -0
  27. data/lib/objects/exception/interactive_session_halt.rb +4 -0
  28. data/lib/objects/exception/invalid_bcome_breadcrumb.rb +7 -0
  29. data/lib/objects/exception/invalid_breadcrumb.rb +7 -0
  30. data/lib/objects/exception/invalid_context_command.rb +7 -0
  31. data/lib/objects/exception/invalid_identifier.rb +7 -0
  32. data/lib/objects/exception/invalid_machines_cache_config.rb +7 -0
  33. data/lib/objects/exception/invalid_matcher_query.rb +7 -0
  34. data/lib/objects/exception/invalid_meta_data_config.rb +7 -0
  35. data/lib/objects/exception/invalid_network_config.rb +7 -0
  36. data/lib/objects/exception/invalid_network_driver_type.rb +7 -0
  37. data/lib/objects/exception/invalid_proxy_config.rb +7 -0
  38. data/lib/objects/exception/invalid_regexp_matcher_in_registry.rb +7 -0
  39. data/lib/objects/exception/invalid_registry_arguments_type.rb +7 -0
  40. data/lib/objects/exception/invalid_registry_data_config.rb +7 -0
  41. data/lib/objects/exception/invalid_restriction_key_in_registry.rb +7 -0
  42. data/lib/objects/exception/invalid_ssh_config.rb +7 -0
  43. data/lib/objects/exception/inventories_cannot_have_subviews.rb +7 -0
  44. data/lib/objects/exception/malformed_command_line_arguments.rb +7 -0
  45. data/lib/objects/exception/method_invocation_requires_parameter.rb +7 -0
  46. data/lib/objects/exception/method_name_conflict_in_registry.rb +7 -0
  47. data/lib/objects/exception/missing_argument_for_registry_command.rb +7 -0
  48. data/lib/objects/exception/missing_description_on_view.rb +7 -0
  49. data/lib/objects/exception/missing_execute_on_registry_object.rb +7 -0
  50. data/lib/objects/exception/missing_identifier_on_view.rb +7 -0
  51. data/lib/objects/exception/missing_ip_address_on_server.rb +7 -0
  52. data/lib/objects/exception/missing_network_config.rb +7 -0
  53. data/lib/objects/exception/missing_params_for_rsync.rb +7 -0
  54. data/lib/objects/exception/missing_params_for_scp.rb +7 -0
  55. data/lib/objects/exception/missing_subselection_key.rb +7 -0
  56. data/lib/objects/exception/missing_type_on_view.rb +7 -0
  57. data/lib/objects/exception/no_node_found_for_breadcrumb.rb +7 -0
  58. data/lib/objects/exception/no_node_named_by_identifier.rb +7 -0
  59. data/lib/objects/exception/node_identifiers_must_be_unique.rb +7 -0
  60. data/lib/objects/exception/orchestration_script_does_not_exist.rb +7 -0
  61. data/lib/objects/exception/proxy_host_node_does_not_have_public_ip_address.rb +7 -0
  62. data/lib/objects/exception/unknown_method_for_namespace.rb +7 -0
  63. data/lib/objects/interactive/session.rb +45 -0
  64. data/lib/objects/interactive/session_item/base.rb +36 -0
  65. data/lib/objects/interactive/session_item/capture_input.rb +20 -0
  66. data/lib/objects/interactive/session_item/transparent_ssh.rb +111 -0
  67. data/lib/objects/modules/context.rb +13 -0
  68. data/lib/objects/modules/registry_management.rb +14 -0
  69. data/lib/objects/modules/ui_output.rb +9 -0
  70. data/lib/objects/modules/workspace_commands.rb +198 -0
  71. data/lib/objects/modules/workspace_menu.rb +128 -0
  72. data/lib/objects/node/attributes.rb +47 -0
  73. data/lib/objects/node/base.rb +248 -0
  74. data/lib/objects/node/cache_handler.rb +24 -0
  75. data/lib/objects/node/collection.rb +51 -0
  76. data/lib/objects/node/factory.rb +108 -0
  77. data/lib/objects/node/inventory/base.rb +88 -0
  78. data/lib/objects/node/inventory/defined.rb +112 -0
  79. data/lib/objects/node/inventory/subselect.rb +54 -0
  80. data/lib/objects/node/meta/base.rb +36 -0
  81. data/lib/objects/node/meta/cloud.rb +4 -0
  82. data/lib/objects/node/meta/local.rb +4 -0
  83. data/lib/objects/node/meta_data_factory.rb +23 -0
  84. data/lib/objects/node/meta_data_loader.rb +32 -0
  85. data/lib/objects/node/resources/base.rb +98 -0
  86. data/lib/objects/node/resources/inventory.rb +25 -0
  87. data/lib/objects/node/resources/sub_inventory.rb +56 -0
  88. data/lib/objects/node/server/base.rb +218 -0
  89. data/lib/objects/node/server/dynamic.rb +39 -0
  90. data/lib/objects/node/server/static.rb +31 -0
  91. data/lib/objects/orchestration/base.rb +13 -0
  92. data/lib/objects/orchestrator.rb +24 -0
  93. data/lib/objects/parser/bread_crumb.rb +31 -0
  94. data/lib/objects/progress_bar.rb +30 -0
  95. data/lib/objects/registry/arguments/base.rb +36 -0
  96. data/lib/objects/registry/arguments/command_line.rb +35 -0
  97. data/lib/objects/registry/arguments/console.rb +15 -0
  98. data/lib/objects/registry/command/base.rb +66 -0
  99. data/lib/objects/registry/command/external.rb +55 -0
  100. data/lib/objects/registry/command/group.rb +76 -0
  101. data/lib/objects/registry/command/internal.rb +34 -0
  102. data/lib/objects/registry/command_list.rb +33 -0
  103. data/lib/objects/registry/loader.rb +70 -0
  104. data/lib/objects/ssh/bootstrap.rb +19 -0
  105. data/lib/objects/ssh/command.rb +46 -0
  106. data/lib/objects/ssh/command_exec.rb +65 -0
  107. data/lib/objects/ssh/connection_handler.rb +101 -0
  108. data/lib/objects/ssh/driver.rb +204 -0
  109. data/lib/objects/ssh/proxy_data.rb +56 -0
  110. data/lib/objects/ssh/script_exec.rb +43 -0
  111. data/lib/objects/system/local.rb +30 -0
  112. data/lib/objects/workspace.rb +75 -0
  113. data/patches/irb.rb +20 -7
  114. data/patches/string.rb +75 -0
  115. data/patches/string_stylesheet.rb +61 -0
  116. metadata +175 -93
  117. data/bin/bcome-bash-setup +0 -18
  118. data/bin/bcome-setup +0 -43
  119. data/bin/boot.rb +0 -148
  120. data/bin/boot_no_shell.rb +0 -3
  121. data/filters/ec2_filter.rb +0 -12
  122. data/lib/bcome/version.rb +0 -3
  123. data/lib/become_object.rb +0 -111
  124. data/lib/boot.rb +0 -13
  125. data/lib/command.rb +0 -56
  126. data/lib/context_functions.rb +0 -65
  127. data/lib/filters/base.rb +0 -10
  128. data/lib/filters/ec2_filter.rb +0 -4
  129. data/lib/functions.rb +0 -70
  130. data/lib/helpers/command_helper.rb +0 -13
  131. data/lib/helpers/environment_ssh.rb +0 -122
  132. data/lib/helpers/fog_helper.rb +0 -108
  133. data/lib/helpers/instance_command.rb +0 -71
  134. data/lib/helpers/instance_ssh.rb +0 -83
  135. data/lib/helpers/selections.rb +0 -117
  136. data/lib/interactive/interactive_session_halt.rb +0 -4
  137. data/lib/interactive/session.rb +0 -44
  138. data/lib/interactive/session_item/base.rb +0 -30
  139. data/lib/interactive/session_item/transparent_ssh.rb +0 -133
  140. data/lib/nodes/base.rb +0 -60
  141. data/lib/nodes/environment.rb +0 -30
  142. data/lib/nodes/estate.rb +0 -44
  143. data/lib/nodes/instance.rb +0 -94
  144. data/lib/nodes/platform.rb +0 -17
  145. data/lib/nodes/view.rb +0 -31
  146. data/lib/object.rb +0 -21
  147. data/lib/orchestrator/command_group/base.rb +0 -56
  148. data/lib/orchestrator/command_group/custom.rb +0 -13
  149. data/lib/orchestrator/command_group/direct.rb +0 -53
  150. data/lib/orchestrator/direct_command/group.rb +0 -21
  151. data/lib/orchestrator/direct_command/instance.rb +0 -19
  152. data/lib/orchestrator/factory.rb +0 -38
  153. data/lib/orchestrator/loader.rb +0 -47
  154. data/lib/orchestrator/node_target/all.rb +0 -14
  155. data/lib/orchestrator/node_target/all_excluding_roles.rb +0 -14
  156. data/lib/orchestrator/node_target/all_with_roles.rb +0 -14
  157. data/lib/orchestrator/node_target/base.rb +0 -43
  158. data/lib/orchestrator/node_target/single.rb +0 -12
  159. data/lib/orchestrator/recipe.rb +0 -60
  160. data/lib/orchestrator/registry.rb +0 -37
  161. data/lib/orchestrator/validate_and_set.rb +0 -10
  162. data/lib/patches/string.rb +0 -86
  163. data/lib/progress_bar.rb +0 -31
  164. data/lib/render_irb.rb +0 -53
  165. data/lib/scp.rb +0 -40
  166. data/lib/ssh.rb +0 -51
  167. data/lib/stack/base.rb +0 -148
  168. data/lib/stack/environment.rb +0 -222
  169. data/lib/stack/estate.rb +0 -50
  170. data/lib/stack/instance.rb +0 -130
  171. data/lib/stack/platform.rb +0 -74
  172. data/lib/stack/view.rb +0 -56
  173. data/lib/workspace_context.rb +0 -40
data/bin/bcome-bash-setup DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # (C) Guillaume Roderick (webzakimbo)
4
- # MIT licence.
5
-
6
- require 'fileutils'
7
-
8
- gem_install_path = File.dirname(__FILE__)
9
-
10
- FileUtils::mkdir_p("#{ENV["HOME"]}/.bcome")
11
- FileUtils::mkdir_p("#{ENV["HOME"]}/.bcome/bin")
12
-
13
- cp_bcome_bash = "cp #{gem_install_path}/../bash/experimental_shortcuts.sh ~/.bcome/bin"
14
- system(cp_bcome_bash)
15
-
16
- puts "\nExperimental bash shortcuts installed. Please ensure you add the bcome bash files to $PATH in your .bashrc"
17
- puts "\ne.g. export PATH=\"$PATH:$HOME/.bcome/bin\""
18
- exit 0
data/bin/bcome-setup DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # (C) Guillaume Roderick (webzakimbo)
4
- # MIT licence.
5
-
6
- require 'fileutils'
7
- bcome_resource_dir = "bcome"
8
-
9
- config_dir = "#{bcome_resource_dir}/config"
10
- filters_dir = "#{bcome_resource_dir}/filters"
11
- patches_dir = "#{bcome_resource_dir}/patches"
12
- static_instances_dir = "#{config_dir}/static_instances"
13
-
14
- ## INSTALL APPLICATION DIRECTORIES
15
- directories = [
16
- filters_dir,
17
- patches_dir,
18
- static_instances_dir
19
- ]
20
-
21
- directories.each do | directory |
22
- FileUtils::mkdir_p(directory)
23
- end
24
-
25
- gem_install_path = File.dirname(__FILE__)
26
- conf_example_path = "#{gem_install_path}/../documentation/examples"
27
- application_path = Dir.pwd
28
-
29
- ["platform.yml-example","network.yml-example", "functions.yml-example"].each do |example_conf|
30
- transfer_cmd = "rsync -aq #{conf_example_path}/#{example_conf} #{application_path}/#{config_dir}/#{example_conf}"
31
- system(transfer_cmd)
32
- end
33
-
34
- ## Copy our patches over
35
- patches_cp_cmd = "cp #{gem_install_path}/../patches/irb.rb #{application_path}/bcome/patches/"
36
- system(patches_cp_cmd)
37
-
38
- ## And copy our filters
39
- filters_cp_cmd = "rsync -aq #{gem_install_path}/../filters/ec2_filter.rb #{application_path}/bcome/filters/"
40
- system(filters_cp_cmd)
41
-
42
-
43
- exit 0
data/bin/boot.rb DELETED
@@ -1,148 +0,0 @@
1
-
2
-
3
- extensions_init_path = "#{Dir.pwd}/bcome/extensions_initializer.rb"
4
- load extensions_init_path if File.exist?(extensions_init_path)
5
-
6
- ### Boot up bcome - used by the shell & exterior bcome processes
7
- unless @no_shell
8
- Dir[Dir.pwd + "/bcome/patches/**/*.rb"].each {|file| load file }
9
- end
10
-
11
- VERBOSE = true
12
- START_PROMPT = "bcome"
13
-
14
- # The ssh_mode identifier in platforms.yml signifying that this platform is to be accessed via an SSH bastion machine
15
- SSH_JUMP_MODE_IDENTIFIER = "jump"
16
-
17
- # The ssh mode identifier in platforms.yml signifying that this platform is to be accessed directly
18
- SSH_DIRECT_MODE_IDENTIFIER = "direct"
19
-
20
- # The SSH role in instances.yml signifying that an instance is an SSJ jump host
21
- SSH_JUMP_HOST_ROLE_IDENTIFIER = "sshjumphost"
22
-
23
- ## The base resource classes - may be overriden
24
- PLATFORM_STACK_KLASS = ::Bcome::Stack::Platform
25
- ENV_STACK_KLASS = ::Bcome::Stack::Environment
26
- INSTANCE_STACK_KLASS = ::Bcome::Stack::Instance
27
-
28
- ##################
29
- ## DEPENDENCIES ##
30
- ##################
31
-
32
- ## Filters are loaded lower down as modules, and hence need to be include first
33
- Dir[Dir.pwd + "/bcome/filters/**/*.rb"].each {|file| load file }
34
-
35
- quick_contexts = []
36
-
37
- BECOME = ::Bcome::WorkspaceContext.new
38
- ESTATE = ::Bcome::Stack::Estate.new
39
- RENDER = ::Bcome::RenderIrb.new
40
-
41
- ###########################
42
- ## MANAGE QUICK CONTEXTS #
43
- ###########################
44
-
45
- quick_context = ENV['bcome_context'] ? ENV['bcome_context'] : ARGV[0]
46
-
47
- quick_contexts = []
48
-
49
- if quick_context
50
-
51
- ## Our context might be a shortcut context, in which case load it
52
- quick_context =~ /(.+):(.+)/
53
- platform_key = $1
54
- context_reference = $2
55
-
56
- if platform_key && context_reference
57
- if platform = ESTATE.resource_for_identifier(platform_key)
58
- if platform.has_quick_contexts? && (context = platform.quick_context_for_reference(context_reference))
59
- quick_contexts = context[:keys]
60
- end
61
- end
62
- end
63
-
64
- unless quick_contexts.any? # we didn't find a shortcut
65
- quick_contexts = quick_context.split(":")
66
- end
67
- end
68
-
69
- direct_commands = ["ls", "run", "ssh", "interactive"] # direct command executions that do not require an irb shell
70
- @direct_shell_commands = ["interactive"] # where we need to jump into a context method directly, but require an irb shell
71
- @no_shell = true if (direct_commands - @direct_shell_commands).include?(quick_contexts.last)
72
-
73
- #########################
74
- ## QUICK CONTEXT & BOOT #
75
- #########################
76
-
77
- @context_object = ESTATE
78
-
79
- unless @no_shell
80
- IRB.setup nil
81
- IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
82
- end
83
-
84
- if quick_contexts.any?
85
- @context_object.init
86
-
87
- is_first_context = true
88
-
89
- spawn = false
90
- quick_contexts.each_with_index do |resource_context_key, index|
91
-
92
- if direct_commands.include?(resource_context_key) && (index == (quick_contexts.size - 1))
93
- unless @context_object.node.respond_to?(resource_context_key.to_sym)
94
- puts "You cannot invoke '#{resource_context_key}' at this namespace level".danger
95
- exit!
96
- end
97
- @direct_command = resource_context_key
98
- @direct_command_on = @context_object
99
- break
100
- end
101
-
102
- next_context_resource = @context_object.resource_for_identifier(resource_context_key)
103
-
104
- # If we can't find our context breadcrumb, the user is perhaps specifying a direct command to be run
105
- # This is used to key into a breadcrumb context object, and then directly execute a custom command (either a context command, or one defined through
106
- # orchestration on it).
107
- # e.g. you have a context command called 'deploy'. You may want to do the following:
108
- # bcome platform:environment:deploy
109
- unless next_context_resource && index <= (quick_contexts.size - 1)
110
- if @context_object.respond_to_bcome_context_method?(resource_context_key.to_sym)
111
- @no_shell = true
112
- @direct_execute_method = resource_context_key.to_sym
113
- break
114
- end
115
- end
116
-
117
- # Initialize our object namespace, but only from our lowest level namespace object. This
118
- # ensures that we don't load more than we need.
119
- if is_first_context
120
- next_context_resource = ESTATE if next_context_resource.nil?
121
- next_context_resource.init
122
- is_first_context = false
123
- end
124
-
125
- if next_context_resource.nil?
126
- if @context_object.respond_to?(resource_context_key)
127
- @context_object.send(resource_context_key)
128
- exit!
129
- else
130
- puts "Cannot find any resource object named: #{resource_context_key}. Please check your breadcrumb and try again".failure
131
- if @context_object.responds_to_list?
132
- puts "\nYou may have been attempting to key into one of the following: ".failure
133
- puts @context_object.mini_list + "\n"
134
- end
135
- exit!
136
- end
137
- end
138
-
139
- BECOME.set(next_context_resource, @context_object, spawn) unless @no_shell
140
- @context_object = next_context_resource
141
- end
142
-
143
- B_PIN = @context_object
144
- B_PIN.init
145
- else
146
- B_PIN = ESTATE
147
- ESTATE.init
148
- end
data/bin/boot_no_shell.rb DELETED
@@ -1,3 +0,0 @@
1
-
2
- @no_shell = true
3
- load Bcome::Boot.boot_path
@@ -1,12 +0,0 @@
1
- module ::Bcome::Filter
2
- class Ec2Filter < ::Bcome::Filter::Base
3
-
4
- def by_group_on_environment
5
- env_string = @environment.meta_data[:environment]
6
- return @resources.select{|resource|
7
- resource.groups.first == env_string
8
- }
9
- end
10
-
11
- end
12
- end
data/lib/bcome/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Bcome
2
- VERSION = "0.7.0"
3
- end
data/lib/become_object.rb DELETED
@@ -1,111 +0,0 @@
1
- module ::Bcome::BecomeObject
2
-
3
- require 'yaml'
4
-
5
- CONFIGS_PATH = "bcome/config"
6
-
7
- def identifier
8
- raise "Missing method 'identifier' - this should uniquely identify your workspace context object."
9
- end
10
-
11
- def become_identifier
12
- "#{previous_workspace_object.send(:become_identifier)}> #{identifier}"
13
- end
14
-
15
- def local_download_path
16
- "#{Dir.pwd}/downloads#{namespace}"
17
- end
18
-
19
- def namespace
20
- "#{previous_workspace_object.send(:namespace)}/#{identifier}"
21
- end
22
-
23
- def context_breadcrumb
24
- breadcrumb = namespace.gsub("/", ":")
25
- breadcrumb.slice!(0)
26
- return breadcrumb
27
- end
28
-
29
- def previous_workspace_object=(object)
30
- @previous_workspace_object = object
31
- end
32
-
33
- def previous_workspace_object
34
- @previous_workspace_object
35
- end
36
-
37
- def main_context=(main_context)
38
- @main_context = main_context
39
- end
40
-
41
- def main_context
42
- @main_context
43
- end
44
-
45
- def has_main_context?
46
- !@main_context.nil?
47
- end
48
-
49
- def resources
50
- @resources ||= do_load_resources
51
- end
52
-
53
- def resource_identifiers
54
- @resource_identifiers ||= resources.collect(&:identifier)
55
- end
56
-
57
- def identifier_for(resource)
58
- r = resource.respond_to?(:identifier) ? resource.identifier : resource.to_s
59
- return r
60
- end
61
-
62
- def has_potential_resources?
63
- respond_to?(:config_path) # No path to config, no resources...
64
- end
65
-
66
- def is_stack_level_resource?(constant_name)
67
- return unless has_potential_resources?
68
- potential_resource_name = constant_name.to_s
69
- return false unless resource_identifiers.any?
70
- return resource_identifiers.select{|resource| identifier_for(resource) == potential_resource_name }.any?
71
- end
72
-
73
- def do_load_resources
74
- config = YAML.load_file(config_path)
75
- collection_klass.collection_from_config(self, config)
76
- end
77
-
78
- def resource_for_identifier(identifier)
79
- return nil unless has_sub_nodes? && resources
80
- matches = resources.select{|resource| resource.identifier.to_sym == identifier.to_sym }
81
- raise "Retrieved more than one match for #{collection_key} '#{identifier}'. Selection is ambiguous" if matches.size > 1
82
- return matches.first
83
- end
84
-
85
- def all_items
86
- return [] unless resources
87
- resources.collect(&:identifier)
88
- end
89
-
90
- def responds_to_list?
91
- true
92
- end
93
-
94
- def mini_list
95
- raise "Namespace does not respond to list" unless responds_to_list?
96
- return resources.collect(&:identifier).join(", ").friendly
97
- end
98
-
99
- def list
100
- if responds_to_list?
101
- ::RENDER.list_items(collection_key, resources)
102
- render_servers_not_returned_by_filtered_lookup if respond_to?(:render_servers_not_returned_by_filtered_lookup)
103
- else
104
- puts "\n" + "No list function at this level".warning + "\n\n"
105
- puts "Enter 'menu' for all available options".menu_item_white + "\n\n"
106
- end
107
- return
108
- end
109
- alias :ls :list
110
- alias :l :list
111
- end
data/lib/boot.rb DELETED
@@ -1,13 +0,0 @@
1
- module Bcome
2
- class Boot
3
-
4
- def self.no_shell_boot_path
5
- return "#{File.dirname(__FILE__)}/../bin/boot_no_shell.rb"
6
- end
7
-
8
- def self.boot_path
9
- return "#{File.dirname(__FILE__)}/../bin/boot.rb"
10
- end
11
-
12
- end
13
- end
data/lib/command.rb DELETED
@@ -1,56 +0,0 @@
1
- class ::Bcome::Command
2
-
3
- # Wraps a command. Convenient flex-point for logging etc
4
-
5
- attr_reader :command, :stdout, :stderr, :exit_code, :exit_signal, :instance, :bootstrap, :success_exit_codes
6
-
7
- def initialize(params)
8
- @command = params[:command]
9
- @instance = params[:instance]
10
- @bootstrap = params[:bootstrap] # whether to run this in bootstrap mode or not
11
- @success_exit_codes = params[:success_exit_codes]
12
-
13
- @stdout = ""
14
- @stderr = ""
15
- @exit_code = nil
16
- @exit_signal = nil
17
- end
18
-
19
- def pretty_result
20
- return is_success? ? "success".success : "failure".failure
21
- end
22
-
23
- def bootstrap=(bootstrap_value)
24
- @bootstrap = bootstrap_value
25
- end
26
-
27
- def output
28
- command_output = is_success? ? @stdout : "Exit code: #{@exit_code}\n\nSTDERR: #{@stderr}"
29
- return "\n#{command_output}"
30
- end
31
-
32
- def is_success?
33
- success_exit_codes.include?(exit_code.to_s)
34
- end
35
-
36
- def success_exit_codes
37
- return @success_exit_codes ? @success_exit_codes : ["0"]
38
- end
39
-
40
- def stdout=(data)
41
- @stdout = data
42
- end
43
-
44
- def stderr=(data)
45
- @stderr = data
46
- end
47
-
48
- def exit_code=(data)
49
- @exit_code = data
50
- end
51
-
52
- def exit_signal(data)
53
- @exit_signal = data
54
- end
55
-
56
- end
@@ -1,65 +0,0 @@
1
- module Bcome::ContextFunctions
2
-
3
- CONFIGS_PATH = "bcome/config"
4
-
5
- def execute_command_for_context(context_command, arguments = [])
6
- arguments.flatten!
7
- if arguments.any? && context_command[:executed_command_with_args]
8
- raw_command = context_command[:executed_command_with_args]
9
- arguments.each_with_index {|argument, index |
10
- raw_command.gsub!("%#{index+1}%",argument)
11
- }
12
- full_command = raw_command
13
- else
14
- full_command = context_command[:executed_command]
15
- end
16
- full_command += " bcome_context=\"#{context_breadcrumb}\""
17
-
18
- run_local(full_command)
19
- end
20
-
21
- def command_for_context(command)
22
- return false unless context_cmd_functions
23
- return false if !context_cmd_functions.any?
24
-
25
- ccfs = context_cmd_functions.select{|ccf| ccf[:command].to_s == command.to_s }
26
- raise "Multiple context commands found at context level #{context_breadcrumb} for command key #{command}" if ccfs.size > 1
27
- return ccfs.first
28
- end
29
-
30
- def context_commands
31
- if context_cmd_functions && context_cmd_functions.any?
32
- description = "\n\s\s" + "Context Commands".menu_title_green + "\n"
33
- context_cmd_functions.each_with_index do |context_function, index|
34
- description += "\n\s\s\s#{index+1}. #{context_function[:description].menu_item_green}"
35
- description += "\n\s\s\sExecuted command:".menu_item_cyan + "\s#{context_function[:executed_command]} bcome_context=\"#{context_breadcrumb}\""
36
- description += "\n\s\s\sUsage:".menu_item_cyan + "\s#{context_function[:command].command}"
37
- description += "\n"
38
- end
39
- end
40
- return description
41
- end
42
-
43
- def context_cmd_functions
44
- return [] unless has_context_functions_config?
45
- @context_cmd_functions ||= load_context_cmd_functions
46
- end
47
-
48
- def has_context_cmd_functions?
49
- !context_cmd_functions.nil?
50
- end
51
-
52
- def load_context_cmd_functions
53
- configs = YAML.load_file(context_cmd_config_path)
54
- return configs[context_breadcrumb]
55
- end
56
-
57
- def context_cmd_config_path
58
- "#{CONFIGS_PATH}/context_functions.yml"
59
- end
60
-
61
- def has_context_functions_config?
62
- File.exist?(context_cmd_config_path)
63
- end
64
-
65
- end