Sha256: 7e79d0554d0f71f8d21b66859415b834c8a52d4a88497b182707648f383311c3

Contents?: true

Size: 1.89 KB

Versions: 9

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module Extension
  class Command
    class Register < ExtensionCommand
      prerequisite_task ensure_project_type: :extension

      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
        ShopifyCli::Context.new.message("register.help", ShopifyCli::TOOL_NAME)
      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

9 entries across 9 versions & 1 rubygems

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