Sha256: 8af1fdc9d8fb5f4254650b0e4b5571cea30179bf53aa5199785ebf2927e1eb7c
Contents?: true
Size: 1.42 KB
Versions: 9
Compression:
Stored size: 1.42 KB
Contents
module Extension module Forms module Questions class AskName include ShopifyCli::MethodObject property! :ctx property :name property :prompt, accepts: ->(prompt) { prompt.respond_to?(:call) }, default: -> { CLI::UI::Prompt.method(:ask) } def call(project_details) if theme_app_extension?(project_details) project_details.name = name || "theme-app-extension" else project_details.name = ask_with_reprompt( initial_value: name, break_condition: -> (current_name) { Models::Registration.valid_title?(current_name) }, prompt_message: ctx.message("create.ask_name"), reprompt_message: ctx.message("create.invalid_name", Models::Registration::MAX_TITLE_LENGTH) ) end project_details end private def theme_app_extension?(project_details) project_details&.type&.identifier == "THEME_APP_EXTENSION" end def ask_with_reprompt(initial_value:, break_condition:, prompt_message:, reprompt_message:) value = initial_value reprompt = false until break_condition.call(value) ctx.puts(reprompt_message) if reprompt value = prompt.call(prompt_message)&.strip reprompt = true end value end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems