Class: ShopifyCLI::Commands::Whoami

Inherits:
ShopifyCLI::Command show all
Defined in:
lib/shopify_cli/commands/whoami.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



23
24
25
# File 'lib/shopify_cli/commands/whoami.rb', line 23

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

Instance Method Details

#call(_args, _name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shopify_cli/commands/whoami.rb', line 6

def call(_args, _name)
  shop = ShopifyCLI::DB.get(:shop)
  org_id = ShopifyCLI::DB.get(:organization_id)
  org = ShopifyCLI::PartnersAPI::Organizations.fetch(@ctx, id: org_id) unless org_id.nil?

  output = if shop.nil? && org.nil?
    @ctx.message("core.whoami.not_logged_in", ShopifyCLI::TOOL_NAME)
  elsif !shop.nil? && org.nil?
    @ctx.message("core.whoami.logged_in_shop_only", shop)
  elsif shop.nil? && !org.nil?
    @ctx.message("core.whoami.logged_in_partner_only", org["businessName"])
  else
    @ctx.message("core.whoami.logged_in_partner_and_shop", shop, org["businessName"])
  end
  @ctx.puts(output)
end