Sha256: a5886696f1e47f32e93322e016cc50b9af63924a9302977354a43408acc81be7

Contents?: true

Size: 1.11 KB

Versions: 22

Compression:

Stored size: 1.11 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)
          if template_required?(project_details)
            project_details.template = template || choose_interactively(project_details)
          end
          project_details
        end

        private

        def template_required?(project_details)
          type = project_details&.type&.identifier
          Models::DevelopmentServerRequirements.supported?(type)
        end

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.35.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.34.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.33.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.33.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.32.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.32.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.31.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.30.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.29.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.28.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.27.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.26.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.25.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.24.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.23.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.22.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.21.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.20.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.20.0 lib/project_types/extension/forms/questions/ask_template.rb