Sha256: a53b8735c31e277c8cd9201347a002c621f9c6b64e5c543fd401832823966e33

Contents?: true

Size: 1.91 KB

Versions: 8

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module Extension
  module Commands
    class Register < ExtensionCommand
      def call(_args, _command_name)
        CLI::UI::Frame.open(@ctx.message("register.frame_title")) do
          @ctx.abort(@ctx.message("register.already_registered")) if project.registered?

          should_continue = confirm_registration
          registration = should_continue ? register_extension : abort_not_registered

          update_project_files(registration)

          @ctx.puts(@ctx.message("register.success", project.title))
          @ctx.puts(@ctx.message("register.success_info"))
        end
      end

      def self.help
        <<~HELP
          Register your local extension to a Shopify app
              Usage: {{command:#{ShopifyCli::TOOL_NAME} register}}
        HELP
      end

      private

      def confirm_registration
        @ctx.puts(@ctx.message("register.confirm_info", specification_handler.name))
        CLI::UI::Prompt.confirm(@ctx.message("register.confirm_question"))
      end

      def register_extension
        @ctx.puts(@ctx.message("register.waiting_text"))

        Tasks::CreateExtension.call(
          context: @ctx,
          api_key: app.api_key,
          type: specification_handler.graphql_identifier,
          title: project.title,
          config: {},
          extension_context: specification_handler.extension_context(@ctx)
        )
      end

      def update_project_files(registration)
        ExtensionProject.write_env_file(
          context: @ctx,
          api_key: app.api_key,
          api_secret: app.secret,
          registration_id: registration.id,
          registration_uuid: registration.uuid,
          title: project.title
        )
      end

      def app
        @app ||= project.app
      end

      def abort_not_registered
        @ctx.puts(@ctx.message("register.confirm_abort"))
        raise ShopifyCli::AbortSilent
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shopify-cli-1.14.0 lib/project_types/extension/commands/register.rb
shopify-cli-1.13.1 lib/project_types/extension/commands/register.rb
shopify-cli-1.13.0 lib/project_types/extension/commands/register.rb
shopify-cli-1.12.0 lib/project_types/extension/commands/register.rb
shopify-cli-1.11.0 lib/project_types/extension/commands/register.rb
shopify-cli-1.10.0 lib/project_types/extension/commands/register.rb
shopify-cli-1.9.1 lib/project_types/extension/commands/register.rb
shopify-cli-1.9.0 lib/project_types/extension/commands/register.rb