Sha256: b851fd388fc7ad53e84c639489c212cea7693e5f9c3834665ca044e5df4659ff

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Script
  module Forms
    class Create < ShopifyCli::Form
      flag_arguments :extension_point, :name, :language, :description

      def ask
        self.name = valid_name
        self.description ||= ask_description
        self.extension_point ||= ask_extension_point
        self.language = ask_language
      end

      private

      def ask_extension_point
        CLI::UI::Prompt.ask(
          @ctx.message("script.forms.create.select_extension_point"),
          options: Layers::Application::ExtensionPoints.non_deprecated_types
        )
      end

      def ask_name
        CLI::UI::Prompt.ask(@ctx.message("script.forms.create.script_name"))
      end

      def ask_description
        CLI::UI::Prompt.ask(@ctx.message("script.forms.create.description"))
      end

      def valid_name
        n = (name || ask_name).downcase.gsub(" ", "_")
        return n if n.match?(/^[0-9A-Za-z_-]*$/)
        raise Errors::InvalidScriptNameError
      end

      def ask_language
        if language
          if Layers::Application::ExtensionPoints.supported_language?(type: extension_point, language: language)
            return language.downcase
          else
            raise Errors::InvalidLanguageError.new(language, extension_point)
          end
        end

        all_languages = Layers::Application::ExtensionPoints.languages(type: extension_point)
        return all_languages.first if all_languages.count == 1

        CLI::UI::Prompt.ask(
          ctx.message("script.forms.create.select_language"),
          options: all_languages
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shopify-cli-1.8.0 lib/project_types/script/forms/create.rb
shopify-cli-1.7.1 lib/project_types/script/forms/create.rb
shopify-cli-1.7.0 lib/project_types/script/forms/create.rb