Sha256: 5cae1589043435cf3a05cd08168280bc28784575033232286a1010bee2e6eeb8

Contents?: true

Size: 1.29 KB

Versions: 17

Compression:

Stored size: 1.29 KB

Contents

module Extension
  module Forms
    module Questions
      class AskTemplate
        include ShopifyCLI::MethodObject

        property! :ctx
        property :template, accepts: Models::ServerConfig::Development::VALID_TEMPLATES
        property :prompt,
          accepts: ->(prompt) { prompt.respond_to?(:call) },
          default: -> { CLI::UI::Prompt.method(:ask) }

        def call(project_details)
          return project_details unless template_required?(project_details)
          project_details.template = template || choose_interactively
          project_details
        end

        private

        def template_required?(project_details)
          return false unless extension_server_beta?
          type = project_details&.type&.identifier
          Models::DevelopmentServerRequirements::SUPPORTED_EXTENSION_TYPES.include?(type.downcase)
        end

        def extension_server_beta?
          ShopifyCLI::Shopifolk.check && ShopifyCLI::Feature.enabled?(:extension_server_beta)
        end

        def choose_interactively
          prompt.call(ctx.message("create.ask_template")) do |handler|
            Models::ServerConfig::Development::VALID_TEMPLATES.each do |template|
              handler.option(template) { template }
            end
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shopify-cli-2.15.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.14.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.13.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.12.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.11.2 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.11.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.11.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.10.2 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.10.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.10.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.9.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.8.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.7.4 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.7.3 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.7.2 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.7.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.7.0 lib/project_types/extension/forms/questions/ask_template.rb