Sha256: 6947c9138db623e852ff5012fc53778193b7377a816b02c28e18f62504bc82ec

Contents?: true

Size: 1.64 KB

Versions: 10

Compression:

Stored size: 1.64 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 }
      end

      def call(args, _name)
        language = 'ts'
        cur_dir = @ctx.root

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

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

        project = Layers::Application::CreateScript.call(
          ctx: @ctx,
          language: language,
          script_name: form.name,
          extension_point_type: form.extension_point
        )
        @ctx.puts(@ctx.message('script.create.change_directory_notice', project.script_name))
      rescue Script::Errors::ScriptProjectAlreadyExistsError => e
        UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message('script.create.error.operation_failed'))
      rescue StandardError => e
        ScriptProject.cleanup(ctx: @ctx, script_name: form.name, root_dir: cur_dir) if form
        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

10 entries across 10 versions & 1 rubygems

Version Path
shopify-cli-1.5.0 lib/project_types/script/commands/create.rb
shopify-cli-1.4.1 lib/project_types/script/commands/create.rb
shopify-cli-1.4.0 lib/project_types/script/commands/create.rb
shopify-cli-1.3.1 lib/project_types/script/commands/create.rb
shopify-cli-1.3.0 lib/project_types/script/commands/create.rb
shopify-cli-1.2.0 lib/project_types/script/commands/create.rb
shopify-cli-1.1.2 lib/project_types/script/commands/create.rb
shopify-cli-1.1.1 lib/project_types/script/commands/create.rb
shopify-cli-1.1.0 lib/project_types/script/commands/create.rb
shopify-cli-1.0.5 lib/project_types/script/commands/create.rb