bcome 1.3.6 → 1.4.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.
- checksums.yaml +4 -4
- data/bin/bcome +13 -8
- data/lib/bcome.rb +7 -11
- data/lib/objects/bcome/version.rb +19 -1
- data/lib/objects/bootup.rb +13 -5
- data/lib/objects/command/local.rb +2 -0
- data/lib/objects/config_factory.rb +3 -0
- data/lib/objects/driver/base.rb +36 -4
- data/lib/objects/driver/bucket.rb +6 -4
- data/lib/objects/driver/ec2.rb +35 -4
- data/lib/objects/driver/gcp.rb +124 -0
- data/lib/objects/driver/gcp/authentication/api_key.rb +6 -0
- data/lib/objects/driver/gcp/authentication/oauth.rb +101 -0
- data/lib/objects/driver/gcp/authentication/service_account.rb +7 -0
- data/lib/objects/driver/static.rb +2 -0
- data/lib/objects/encryptor.rb +26 -24
- data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +8 -4
- data/lib/objects/exception/base.rb +14 -10
- data/lib/objects/exception/can_only_subselect_on_inventory.rb +8 -4
- data/lib/objects/exception/cannot_authenticate_to_gcp.rb +11 -0
- data/lib/objects/exception/cannot_find_internal_registry_klass.rb +8 -4
- data/lib/objects/exception/cannot_find_inventory.rb +11 -0
- data/lib/objects/exception/cannot_find_subselection_parent.rb +8 -4
- data/lib/objects/exception/cant_find_key_in_cloud_tags.rb +8 -4
- data/lib/objects/exception/cant_find_key_in_metadata.rb +8 -4
- data/lib/objects/exception/cant_find_proxy_host_by_identifier.rb +8 -4
- data/lib/objects/exception/cant_find_proxy_host_by_namespace.rb +8 -4
- data/lib/objects/exception/could_not_initiate_ssh_connection.rb +8 -4
- data/lib/objects/exception/could_not_initiate_ssh_connection_through_backend_proxy.rb +8 -4
- data/lib/objects/exception/could_not_retrieve_terraform_output.rb +11 -0
- data/lib/objects/exception/deprecation_warning.rb +9 -7
- data/lib/objects/exception/duplicate_command_line_argument_key.rb +8 -4
- data/lib/objects/exception/ec2_driver_missing_provisioning_region.rb +8 -4
- data/lib/objects/exception/failed_to_run_local_command.rb +8 -4
- data/lib/objects/exception/generic.rb +11 -0
- data/lib/objects/exception/interactive_session_halt.rb +6 -2
- data/lib/objects/exception/invalid_bcome_breadcrumb.rb +8 -4
- data/lib/objects/exception/invalid_breadcrumb.rb +8 -4
- data/lib/objects/exception/invalid_context_command.rb +8 -4
- data/lib/objects/exception/invalid_gcp_authentication_scheme.rb +11 -0
- data/lib/objects/exception/invalid_identifier.rb +8 -4
- data/lib/objects/exception/invalid_machines_cache_config.rb +8 -4
- data/lib/objects/exception/invalid_matcher_query.rb +8 -4
- data/lib/objects/exception/invalid_meta_data_config.rb +8 -4
- data/lib/objects/exception/invalid_metadata_encryption_key.rb +8 -4
- data/lib/objects/exception/invalid_network_config.rb +8 -4
- data/lib/objects/exception/invalid_network_driver_type.rb +8 -4
- data/lib/objects/exception/invalid_port_forward_request.rb +11 -0
- data/lib/objects/exception/invalid_proxy_config.rb +8 -4
- data/lib/objects/exception/invalid_regexp_matcher_in_registry.rb +8 -4
- data/lib/objects/exception/invalid_registry_arguments_type.rb +8 -4
- data/lib/objects/exception/invalid_registry_command_name_length.rb +8 -4
- data/lib/objects/exception/invalid_registry_data_config.rb +8 -4
- data/lib/objects/exception/invalid_restriction_key_in_registry.rb +8 -4
- data/lib/objects/exception/invalid_ssh_config.rb +8 -4
- data/lib/objects/exception/inventories_cannot_have_subviews.rb +8 -4
- data/lib/objects/exception/malformed_command_line_arguments.rb +8 -4
- data/lib/objects/exception/method_invocation_requires_parameter.rb +8 -4
- data/lib/objects/exception/method_name_conflict_in_registry.rb +8 -4
- data/lib/objects/exception/missing_argument_for_registry_command.rb +8 -4
- data/lib/objects/exception/missing_description_on_view.rb +8 -4
- data/lib/objects/exception/missing_execute_on_registry_object.rb +8 -4
- data/lib/objects/exception/missing_gcp_authentication_scheme.rb +11 -0
- data/lib/objects/exception/missing_gcp_service_scopes.rb +11 -0
- data/lib/objects/exception/missing_identifier_on_view.rb +8 -4
- data/lib/objects/exception/missing_inventory_contributors.rb +11 -0
- data/lib/objects/exception/missing_ip_address_on_server.rb +8 -4
- data/lib/objects/exception/missing_network_config.rb +8 -4
- data/lib/objects/exception/missing_or_invalid_client_secrets.rb +11 -0
- data/lib/objects/exception/missing_params_for_rsync.rb +8 -4
- data/lib/objects/exception/missing_params_for_scp.rb +8 -4
- data/lib/objects/exception/missing_subselection_key.rb +8 -4
- data/lib/objects/exception/missing_type_on_view.rb +8 -4
- data/lib/objects/exception/no_node_found_for_breadcrumb.rb +8 -4
- data/lib/objects/exception/no_node_named_by_identifier.rb +8 -4
- data/lib/objects/exception/node_identifiers_must_be_unique.rb +8 -4
- data/lib/objects/exception/orchestration_script_does_not_exist.rb +8 -4
- data/lib/objects/exception/proxy_host_node_does_not_have_public_ip_address.rb +8 -4
- data/lib/objects/exception/unknown_dynamic_server_type.rb +11 -0
- data/lib/objects/exception/unknown_method_for_namespace.rb +8 -4
- data/lib/objects/interactive/session.rb +4 -1
- data/lib/objects/interactive/session_item/base.rb +2 -0
- data/lib/objects/interactive/session_item/capture_input.rb +2 -0
- data/lib/objects/interactive/session_item/transparent_ssh.rb +29 -23
- data/lib/objects/loading_bar/handler.rb +80 -0
- data/lib/objects/loading_bar/indicator/base.rb +64 -0
- data/lib/objects/loading_bar/indicator/basic.rb +34 -0
- data/lib/objects/loading_bar/indicator/progress.rb +26 -0
- data/lib/objects/loading_bar/pid_bucket.rb +27 -0
- data/lib/objects/modules/context.rb +13 -9
- data/lib/objects/modules/registry_management.rb +16 -10
- data/lib/objects/modules/ui_output.rb +10 -6
- data/lib/objects/modules/workspace_commands.rb +159 -155
- data/lib/objects/modules/workspace_menu.rb +129 -130
- data/lib/objects/node/attributes.rb +13 -21
- data/lib/objects/node/base.rb +113 -71
- data/lib/objects/node/cache_handler.rb +2 -0
- data/lib/objects/node/collection.rb +10 -9
- data/lib/objects/node/factory.rb +35 -28
- data/lib/objects/node/inventory/base.rb +100 -100
- data/lib/objects/node/inventory/defined.rb +110 -89
- data/lib/objects/node/inventory/merge.rb +43 -0
- data/lib/objects/node/inventory/subselect.rb +64 -46
- data/lib/objects/node/kube/base.rb +51 -0
- data/lib/objects/node/kube/container.rb +9 -0
- data/lib/objects/node/kube/estate.rb +19 -0
- data/lib/objects/node/kube/namespace.rb +24 -0
- data/lib/objects/node/kube/pod.rb +24 -0
- data/lib/objects/node/kube_wrap.rb +26 -0
- data/lib/objects/node/meta/base.rb +8 -1
- data/lib/objects/node/meta/cloud.rb +2 -0
- data/lib/objects/node/meta/local.rb +2 -0
- data/lib/objects/node/meta_data_factory.rb +3 -1
- data/lib/objects/node/meta_data_loader.rb +27 -28
- data/lib/objects/node/resources/base.rb +5 -1
- data/lib/objects/node/resources/inventory.rb +7 -5
- data/lib/objects/node/resources/merged.rb +38 -0
- data/lib/objects/node/resources/sub_inventory.rb +7 -4
- data/lib/objects/node/server/base.rb +88 -66
- data/lib/objects/node/server/dynamic/base.rb +23 -0
- data/lib/objects/node/server/{dynamic.rb → dynamic/ec2.rb} +14 -13
- data/lib/objects/node/server/dynamic/gcp.rb +47 -0
- data/lib/objects/node/server/static.rb +13 -2
- data/lib/objects/orchestration/base.rb +10 -0
- data/lib/objects/orchestration/interactive_terraform.rb +62 -27
- data/lib/objects/orchestrator.rb +22 -0
- data/lib/objects/parser/bread_crumb.rb +3 -1
- data/lib/objects/registry/arguments/base.rb +3 -1
- data/lib/objects/registry/arguments/command_line.rb +6 -1
- data/lib/objects/registry/arguments/console.rb +4 -1
- data/lib/objects/registry/command/base.rb +3 -0
- data/lib/objects/registry/command/external.rb +4 -2
- data/lib/objects/registry/command/group.rb +6 -3
- data/lib/objects/registry/command/internal.rb +3 -1
- data/lib/objects/registry/command/shortcut.rb +17 -9
- data/lib/objects/registry/command_list.rb +2 -0
- data/lib/objects/registry/loader.rb +10 -10
- data/lib/objects/ssh/bootstrap.rb +3 -1
- data/lib/objects/ssh/command.rb +10 -5
- data/lib/objects/ssh/command_exec.rb +13 -9
- data/lib/objects/ssh/connection_wrangler.rb +105 -0
- data/lib/objects/ssh/connector.rb +100 -0
- data/lib/objects/ssh/driver.rb +27 -230
- data/lib/objects/ssh/driver_concerns/command_strings.rb +17 -0
- data/lib/objects/ssh/driver_concerns/connection.rb +78 -0
- data/lib/objects/ssh/driver_concerns/functions.rb +89 -0
- data/lib/objects/ssh/driver_concerns/user.rb +32 -0
- data/lib/objects/ssh/{proxy_data.rb → proxy_hop.rb} +52 -7
- data/lib/objects/ssh/script_exec.rb +4 -1
- data/lib/objects/ssh/tunnel/local_port_forward.rb +5 -6
- data/lib/objects/ssh/tunnel_keeper.rb +21 -0
- data/lib/objects/ssh/window.rb +31 -0
- data/lib/objects/startup.rb +52 -0
- data/lib/objects/system/local.rb +3 -0
- data/lib/objects/terraform/output.rb +41 -0
- data/lib/objects/workspace.rb +3 -14
- data/patches/irb.rb +27 -3
- data/patches/string-encrypt.rb +20 -23
- data/patches/string.rb +5 -1
- data/patches/string_stylesheet.rb +2 -0
- metadata +95 -18
- data/lib/objects/progress_bar.rb +0 -30
- data/lib/objects/ssh/connection_handler.rb +0 -101
- data/lib/objects/terraform/parser.rb +0 -23
- data/lib/objects/terraform/state.rb +0 -40
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class MissingIdentifierOnView < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'One of your views is missing an identifier field'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class MissingIpaddressOnServer < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'A static server must specify either a public or internal ip address'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class MissingNetworkConfig < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'Cannot find network config at'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class MissingParamsForRsync < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
''
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class MissingParamsForScp < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
''
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class MissingSubselectionKey < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'You must set a subselection key when defining a subselection inventory'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class MissingTypeOnView < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'One of your views is missing a type field'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class NoNodeFoundForBreadcrumb < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'No node exists for breadcrumb'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class NoNodeNamedByIdentifier < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'Cannot find identifier within inventory'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class NodeIdentifiersMustBeUnique < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'Node identifiers cannot be ambiguous: '
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class OrchestrationScriptDoesNotExist < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'Cannot find orchestration file at path: '
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class ProxyHostNodeDoesNotHavePublicIp < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'Node missing public ip address, and so cannot be used as a proxy ssh server'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Exception
|
5
|
+
class UnknownMethodForNamespace < ::Bcome::Exception::Base
|
6
|
+
def message_prefix
|
7
|
+
'unknown method or namespace'
|
8
|
+
end
|
5
9
|
end
|
6
10
|
end
|
7
11
|
end
|
@@ -1,10 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Interactive
|
2
4
|
class Session
|
3
5
|
class << self
|
4
6
|
def run(node, session_type, init_data = {})
|
5
7
|
session_end_message = "\ninteractive session ended\n".informational
|
6
8
|
begin
|
7
|
-
|
9
|
+
session_klass = session_type.is_a?(Symbol) ? session_type_to_klass[session_type] : session_type
|
10
|
+
session = ::Bcome::Interactive::Session.new(node, session_klass, init_data)
|
8
11
|
session.start
|
9
12
|
rescue ::Bcome::Exception::InteractiveSessionHalt => e
|
10
13
|
puts session_end_message
|
@@ -1,18 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Interactive::SessionItem
|
2
4
|
class TransparentSsh < ::Bcome::Interactive::SessionItem::Base
|
3
|
-
END_SESSION_KEY = '\\q'
|
4
|
-
HELP_KEY = '\\?'
|
5
|
-
LIST_KEY = '\\l'
|
6
|
-
|
7
|
-
DANGER_CMD = "rm\s+-r|rm\s+-f|rm\s+-fr|rm\s+-rf|rm"
|
5
|
+
END_SESSION_KEY = '\\q'
|
6
|
+
HELP_KEY = '\\?'
|
7
|
+
LIST_KEY = '\\l'
|
8
|
+
RECONNECT_CMD = '\\r'
|
9
|
+
DANGER_CMD = "rm\s+-r|rm\s+-f|rm\s+-fr|rm\s+-rf|rm"
|
8
10
|
|
9
11
|
def machines
|
10
|
-
|
12
|
+
skip_for_hidden = true
|
13
|
+
node.server? ? [node] : node.machines(skip_for_hidden)
|
11
14
|
end
|
12
15
|
|
13
16
|
def do
|
14
17
|
puts ''
|
15
18
|
open_ssh_connections
|
19
|
+
puts "\nINTERACTIVE COMMAND SESSION".underline
|
16
20
|
show_menu
|
17
21
|
puts ''
|
18
22
|
list_machines
|
@@ -22,10 +26,7 @@ module Bcome::Interactive::SessionItem
|
|
22
26
|
def action
|
23
27
|
input = get_input
|
24
28
|
|
25
|
-
if exit?(input)
|
26
|
-
close_ssh_connections
|
27
|
-
return
|
28
|
-
end
|
29
|
+
return if exit?(input)
|
29
30
|
|
30
31
|
if show_menu?(input)
|
31
32
|
show_menu
|
@@ -40,16 +41,13 @@ module Bcome::Interactive::SessionItem
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def show_menu
|
43
|
-
warning = "\
|
44
|
-
|
45
|
-
|
46
|
-
puts "#{warning}#{second_warning}#{info}\n"
|
44
|
+
warning = "\nCommands entered here will be executed on" + "\severy\s".warning + "machine in your selection. \n\nUse with caution or hit \\q if you're unsure what this is."
|
45
|
+
info = "\n\n\\l list machines\n\\q to quit\n\\? this message".informational
|
46
|
+
puts warning + "#{info}\n"
|
47
47
|
end
|
48
48
|
|
49
49
|
def handle_the_unwise(input)
|
50
|
-
if prompt_for_confirmation('Command may be dangerous to run on all machines. Are you sure you want to proceed? [Y|N] > '.error)
|
51
|
-
execute_on_machines(input)
|
52
|
-
end
|
50
|
+
execute_on_machines(input) if prompt_for_confirmation('Command may be dangerous to run on all machines. Are you sure you want to proceed? [Y|N] > '.error)
|
53
51
|
end
|
54
52
|
|
55
53
|
def command_may_be_unwise?(input)
|
@@ -65,7 +63,7 @@ module Bcome::Interactive::SessionItem
|
|
65
63
|
def start_message; end
|
66
64
|
|
67
65
|
def terminal_prompt
|
68
|
-
">\s"
|
66
|
+
"enter a command>\s"
|
69
67
|
end
|
70
68
|
|
71
69
|
def exit?(input)
|
@@ -81,8 +79,8 @@ module Bcome::Interactive::SessionItem
|
|
81
79
|
end
|
82
80
|
|
83
81
|
def open_ssh_connections
|
84
|
-
::Bcome::Ssh::
|
85
|
-
system('clear')
|
82
|
+
::Bcome::Ssh::Connector.connect(node, show_progress: true)
|
83
|
+
# system('clear')
|
86
84
|
end
|
87
85
|
|
88
86
|
def close_ssh_connections
|
@@ -91,20 +89,28 @@ module Bcome::Interactive::SessionItem
|
|
91
89
|
|
92
90
|
def indicate_failed_nodes(unconnected_nodes)
|
93
91
|
unconnected_nodes.each do |node|
|
94
|
-
puts "\s\s - #{node.namespace}"
|
92
|
+
puts "\s\s - #{node.namespace}"
|
95
93
|
end
|
96
94
|
end
|
97
95
|
|
98
96
|
def list_machines
|
99
97
|
puts "\n"
|
100
98
|
machines.each do |machine|
|
101
|
-
puts "
|
99
|
+
puts "- #{machine.namespace}"
|
102
100
|
end
|
103
101
|
end
|
104
102
|
|
105
103
|
def execute_on_machines(user_input)
|
106
104
|
machines.pmap do |machine|
|
107
|
-
|
105
|
+
begin
|
106
|
+
machine.run(user_input)
|
107
|
+
rescue IOError => e
|
108
|
+
puts "Reopening connection to\s".informational + machine.identifier
|
109
|
+
machine.reopen_ssh_connection
|
110
|
+
machine.run(user_input)
|
111
|
+
rescue Exception => e
|
112
|
+
puts "Error connecting to #{machine.identifier} (#{e.message})".error
|
113
|
+
end
|
108
114
|
end
|
109
115
|
end
|
110
116
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module LoadingBar
|
5
|
+
module Handler
|
6
|
+
def start_indicator(config)
|
7
|
+
klass = config[:type] == :progress ? ::Bcome::LoadingBar::Indicator::Progress : ::Bcome::LoadingBar::Indicator::Basic
|
8
|
+
@indicator = klass.new(config)
|
9
|
+
fork_process
|
10
|
+
end
|
11
|
+
|
12
|
+
def stop_indicator
|
13
|
+
signal_stop
|
14
|
+
end
|
15
|
+
|
16
|
+
def cursor
|
17
|
+
::TTY::Cursor
|
18
|
+
end
|
19
|
+
|
20
|
+
def wrap_indicator(config, &block)
|
21
|
+
begin
|
22
|
+
start_indicator(config)
|
23
|
+
cursor.invisible do
|
24
|
+
block.call
|
25
|
+
end
|
26
|
+
rescue IRB::Abort
|
27
|
+
stop_indicator
|
28
|
+
raise ::Bcome::Exception::Generic, 'Interrupt'
|
29
|
+
rescue StandardError => e
|
30
|
+
stop_indicator
|
31
|
+
raise ::Bcome::Exception::Generic, e.message if config[:type] == :basic
|
32
|
+
end
|
33
|
+
stop_indicator
|
34
|
+
end
|
35
|
+
|
36
|
+
def fork_process
|
37
|
+
@pid = fork do
|
38
|
+
Signal.trap(::Bcome::LoadingBar::Indicator::Base::SIGNAL_SUCCESS) do
|
39
|
+
@indicator.increment_success
|
40
|
+
end
|
41
|
+
|
42
|
+
Signal.trap(::Bcome::LoadingBar::Indicator::Base::SIGNAL_FAILURE) do
|
43
|
+
@indicator.increment_failure
|
44
|
+
end
|
45
|
+
|
46
|
+
@indicator.indicate
|
47
|
+
end
|
48
|
+
::Bcome::LoadingBar::PidBucket.instance << @pid
|
49
|
+
end
|
50
|
+
|
51
|
+
def do_signal(signal)
|
52
|
+
::Process.kill(signal, @pid)
|
53
|
+
end
|
54
|
+
|
55
|
+
def signal_stop
|
56
|
+
# Stop the loader
|
57
|
+
do_signal(::Bcome::LoadingBar::Indicator::Base::SIGNAL_STOP)
|
58
|
+
|
59
|
+
# De-register its pid
|
60
|
+
::Bcome::LoadingBar::PidBucket.instance - @pid
|
61
|
+
|
62
|
+
# Show the PARENT process indicator, which has been kept in sync with the forked process. We do this due to race condition where the forked indicator
|
63
|
+
# does not gets final status before it is killed, so that it looks as if it has not completed
|
64
|
+
@indicator.show
|
65
|
+
end
|
66
|
+
|
67
|
+
def signal_success
|
68
|
+
do_signal(::Bcome::LoadingBar::Indicator::Base::SIGNAL_SUCCESS)
|
69
|
+
# Keep parent indicator in sync (see #signal_stop)
|
70
|
+
@indicator.increment_success
|
71
|
+
end
|
72
|
+
|
73
|
+
def signal_failure
|
74
|
+
do_signal(::Bcome::LoadingBar::Indicator::Base::SIGNAL_FAILURE)
|
75
|
+
# Keeo parent indicator in sync (see #signal_stop)
|
76
|
+
@indicator.increment_failure
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|