Sha256: 47f03da8687379d12de239b75724e779eda49d4a9d6b549de06ecacd8eaa02bb

Contents?: true

Size: 957 Bytes

Versions: 2

Compression:

Stored size: 957 Bytes

Contents

module Extension
  module Forms
    module Questions
      class AskType
        include ShopifyCli::MethodObject

        property! :ctx
        property :type
        property :prompt,
          converts: :to_proc,
          default: -> { CLI::UI::Prompt.method(:ask) }

        def call(project_details)
          project_details.tap do |p|
            p.type = type.nil? ? choose_type : validate_given_type(type)
          end
        end

        private

        def validate_given_type(type)
          return Extension.specifications[type] if Extension.specifications.valid?(type)
          ctx.abort(ctx.message("create.invalid_type")) unless type.nil?
        end

        def choose_type
          prompt.call(ctx.message("create.ask_type")) do |handler|
            Extension.specifications.each do |type|
              handler.option("#{type.name} #{type.tagline}") { type }
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify-cli-1.7.1 lib/project_types/extension/forms/questions/ask_type.rb
shopify-cli-1.7.0 lib/project_types/extension/forms/questions/ask_type.rb