Sha256: 5ffd86e58fa75433faaebaaa2e95793f2fdcb4c09966f29dea43126599de6db5

Contents?: true

Size: 937 Bytes

Versions: 9

Compression:

Stored size: 937 Bytes

Contents

require "shopify_cli"

module ShopifyCli
  module Commands
    class Whoami < ShopifyCli::Command
      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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shopify-cli-2.4.0 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.3.0 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.2.2 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.2.1 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.2.0 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.1.0 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.0.2 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.0.1 lib/shopify-cli/commands/whoami.rb
shopify-cli-2.0.0 lib/shopify-cli/commands/whoami.rb