Sha256: 953f48abc118a18e8969a836cae010e04ccced28a70b36962cd17842c2e621b7

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Script
  module Commands
    class Create < ShopifyCli::SubCommand
      options do |parser, flags|
        parser.on("--name=NAME") { |name| flags[:name] = name }
        parser.on("--extension_point=EP_NAME") { |ep_name| flags[:extension_point] = ep_name }
        parser.on("--extension-point=EP_NAME") { |ep_name| flags[:extension_point] = ep_name }
        parser.on("--language=LANGUAGE") { |language| flags[:language] = language }
        parser.on("--no-config-ui") { |no_config_ui| flags[:no_config_ui] = no_config_ui }
      end

      def call(args, _name)
        form = Forms::Create.ask(@ctx, args, options.flags)
        return @ctx.puts(self.class.help) if form.nil?

        unless !form.name.empty? && form.extension_point && form.language
          return @ctx.puts(self.class.help)
        end

        project = Layers::Application::CreateScript.call(
          ctx: @ctx,
          language: form.language,
          script_name: form.name,
          extension_point_type: form.extension_point,
          no_config_ui: options.flags.key?(:no_config_ui)
        )
        @ctx.puts(@ctx.message("script.create.change_directory_notice", project.script_name))
      rescue StandardError => e
        UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message("script.create.error.operation_failed"))
      end

      def self.help
        allowed_values = Script::Layers::Application::ExtensionPoints.types.map { |type| "{{cyan:#{type}}}" }
        ShopifyCli::Context.message("script.create.help", ShopifyCli::TOOL_NAME, allowed_values.join(", "))
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shopify-cli-1.14.0 lib/project_types/script/commands/create.rb
shopify-cli-1.13.1 lib/project_types/script/commands/create.rb
shopify-cli-1.13.0 lib/project_types/script/commands/create.rb
shopify-cli-1.12.0 lib/project_types/script/commands/create.rb
shopify-cli-1.11.0 lib/project_types/script/commands/create.rb
shopify-cli-1.10.0 lib/project_types/script/commands/create.rb
shopify-cli-1.9.1 lib/project_types/script/commands/create.rb
shopify-cli-1.9.0 lib/project_types/script/commands/create.rb