Class: ShopifyCli::Commands::Connect
Instance Attribute Summary
#ctx, #options
Class Method Summary
collapse
Instance Method Summary
collapse
call, call_help, #initialize, options, prerequisite_task, run_prerequisites, subcommand, subcommand_registry
#hidden?, #hidden_feature
Class Method Details
.help ⇒ Object
42
43
44
|
# File 'lib/shopify-cli/commands/connect.rb', line 42
def self.help
ShopifyCli::Context.message('core.connect.help', ShopifyCli::TOOL_NAME)
end
|
Instance Method Details
#ask_project_type ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/shopify-cli/commands/connect.rb', line 25
def ask_project_type
CLI::UI::Prompt.ask(@ctx.message('core.connect.project_type_select')) do |handler|
ShopifyCli::Commands::Create.all_visible_type.each do |type|
handler.option(type.project_name) { type.project_type }
end
end
end
|
#call ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/shopify-cli/commands/connect.rb', line 6
def call(*)
project_type = ask_project_type unless Project.has_current?
if Project.has_current? && Project.current && Project.current.env
@ctx.puts @ctx.message('core.connect.already_connected_warning')
prod_warning = @ctx.message('core.connect.production_warning')
@ctx.puts prod_warning if [:rails, :node].include?(Project.current_project_type)
end
org = ShopifyCli::Tasks::EnsureEnv.call(@ctx, regenerate: true)
write_cli_yml(project_type, org['id']) unless Project.has_current?
api_key = Project.current(force_reload: true).env['api_key']
@ctx.puts(@ctx.message('core.connect.connected', get_app(org['apps'], api_key).first["title"]))
end
|
#get_app(apps, api_key) ⇒ Object
21
22
23
|
# File 'lib/shopify-cli/commands/connect.rb', line 21
def get_app(apps, api_key)
apps.select { |app| app["apiKey"] == api_key }
end
|
#write_cli_yml(project_type, org_id) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/shopify-cli/commands/connect.rb', line 33
def write_cli_yml(project_type, org_id)
ShopifyCli::Project.write(
@ctx,
project_type: project_type,
organization_id: org_id,
)
@ctx.done(@ctx.message('core.connect.cli_yml_saved'))
end
|