Sha256: 756a88e480c6e6e3adc746087ffcd7501dda401b8334e1027cd4622c332d0466

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 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
          end
          project_details
        end

        private

        def template_required?(project_details)
          type = project_details&.type&.identifier
          Models::DevelopmentServerRequirements.supported?(type)
        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

7 entries across 7 versions & 1 rubygems

Version Path
shopify-cli-2.18.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.17.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.16.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.16.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.15.6 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.15.5 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.15.4 lib/project_types/extension/forms/questions/ask_template.rb