Sha256: 5163058dad5e462db8ddb1d225a86e7231cb51b3abc3d3290befc3070ad43c96

Contents?: true

Size: 1.18 KB

Versions: 44

Compression:

Stored size: 1.18 KB

Contents

require "shopify_cli"

module ShopifyCLI
  module Commands
    class Switch < ShopifyCLI::Command
      options do |parser, flags|
        parser.on("-s", "--store=STORE") { |url| flags[:shop] = url }
        # backwards compatibility allow 'shop' for now
        parser.on("--shop=SHOP") { |url| flags[:shop] = url }
      end

      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

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

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.35.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.34.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.33.1 lib/shopify_cli/commands/switch.rb
shopify-cli-2.33.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.32.1 lib/shopify_cli/commands/switch.rb
shopify-cli-2.32.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.31.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.30.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.29.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.28.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.27.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.26.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.25.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.24.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.23.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.22.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.21.0 lib/shopify_cli/commands/switch.rb
shopify-cli-2.20.1 lib/shopify_cli/commands/switch.rb
shopify-cli-2.20.0 lib/shopify_cli/commands/switch.rb