Class: ShopifyCLI::Commands::Switch

Inherits:
ShopifyCLI::Command show all
Defined in:
lib/shopify_cli/commands/switch.rb

Instance Attribute Summary

Attributes inherited from ShopifyCLI::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShopifyCLI::Command

call, call_help, check_node_version, check_ruby_version, check_version, #initialize, options, prerequisite_task, recommend_default_node_range, recommend_default_ruby_range, recommend_node, recommend_ruby, run_prerequisites, subcommand, subcommand_registry

Methods included from Feature::Set

#hidden?, #hidden_feature

Constructor Details

This class inherits a constructor from ShopifyCLI::Command

Class Method Details

.helpObject



34
35
36
# File 'lib/shopify_cli/commands/switch.rb', line 34

def self.help
  ShopifyCLI::Context.message("core.switch.help", ShopifyCLI::TOOL_NAME)
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shopify_cli/commands/switch.rb', line 12

def call(*)
  if Shopifolk.acting_as_shopify_organization?
    @ctx.puts(@ctx.message("core.switch.disabled_as_shopify_org"))
    return
  end

  shop = if options.flags[:shop]
    Login.validate_shop(options.flags[:shop], context: @ctx)
  elsif (org_id = DB.get(:organization_id))
    res = ShopifyCLI::Tasks::SelectOrgAndShop.call(@ctx, organization_id: org_id)
    res[:shop_domain]
  else
    AdminAPI.get_shop_or_abort(@ctx)
    res = ShopifyCLI::Tasks::SelectOrgAndShop.call(@ctx)
    res[:shop_domain]
  end
  DB.set(shop: shop)
  IdentityAuth.new(ctx: @ctx).reauthenticate

  @ctx.puts(@ctx.message("core.switch.success", shop))
end