Module: Strata::CLI::Helpers::CommandContext
Constant Summary
DatasourceHelper::ADAPTER_DRIVER_GEMS
Constants included
from Output
Output::THEME
Instance Method Summary
collapse
#apply_readonly_mode, #create_adapter, #ds_config, #ensure_adapter_driver_gems!, #load_adapter_driver_gems!, #resolve_datasource, #resolve_datasource_value
Methods included from Output
format, pastel, print_error, #print_error, print_hint, #print_hint, print_info, #print_info, print_status, #print_status, print_success, #print_success, print_warning, #print_warning, shell_for, thor_color
Instance Method Details
#adapter ⇒ Object
16
17
18
|
# File 'lib/strata/cli/helpers/command_context.rb', line 16
def adapter
@adapter ||= create_adapter(datasource_key)
end
|
#all_tables ⇒ Object
53
54
55
|
# File 'lib/strata/cli/helpers/command_context.rb', line 53
def all_tables
table_fetch_result[:tables]
end
|
#datasource_key ⇒ Object
24
25
26
|
# File 'lib/strata/cli/helpers/command_context.rb', line 24
def datasource_key
@datasource_key ||= resolve_datasource(prompt: prompt)
end
|
#prompt ⇒ Object
20
21
22
|
# File 'lib/strata/cli/helpers/command_context.rb', line 20
def prompt
@prompt ||= TTY::Prompt.new
end
|
#table_fetch_result ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/strata/cli/helpers/command_context.rb', line 28
def table_fetch_result
@table_fetch_result ||= begin
tables = with_spinner("Fetching tables from #{datasource_key}...") { adapter.tables }
if tables.empty?
say(Output.format(:warning, Prompts::MSG_NO_TABLES_FOUND % datasource_key), nil) if respond_to?(:say)
{tables: [], failed: false}
else
{tables: tables, failed: false}
end
rescue => e
ErrorReporter.log_error(e, context: "create table: failed fetching tables for '#{datasource_key}'")
if ErrorReporter.connection_error?(e)
say(Output.format(:warning, "Could not connect to datasource '#{datasource_key}'."), nil) if respond_to?(:say)
else
say(Output.format(:warning, "Could not fetch tables from datasource '#{datasource_key}'."), nil) if respond_to?(:say)
say(Output.format(:warning, "Reason: #{ErrorReporter.user_message_for(e)}"), nil) if respond_to?(:say)
end
say(Output.format(:dim, "Hint: verify credentials/settings and run 'strata datasource test #{datasource_key}'."), nil) if respond_to?(:say)
say(Output.format(:info, "Details logged to '#{ErrorReporter.log_relative_path}'."), nil) if respond_to?(:say)
{tables: [], failed: true}
end
end
|