Sha256: 85203550bb83b3fdfc3114e4ccdc84fbf6ac5ce9b140ceda3296dfa664fffacd

Contents?: true

Size: 1.78 KB

Versions: 14

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

module Script
  class Command
    class Create < ShopifyCLI::Command::SubCommand
      prerequisite_task :ensure_authenticated

      recommend_default_ruby_range

      options do |parser, flags|
        parser.on("--title=TITLE") { |title| flags[:title] = title }
        parser.on("--api=API_NAME") { |ep_name| flags[:extension_point] = ep_name }
        parser.on("--language=LANGUAGE") { |language| flags[:language] = language }
        parser.on("--branch=BRANCH") { |branch| flags[:branch] = branch }
      end

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

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

        project = Layers::Application::CreateScript.call(
          ctx: @ctx,
          language: options.flags[:language]&.downcase || "wasm",
          sparse_checkout_branch: options.flags[:branch] || "master",
          title: form.title,
          extension_point_type: form.extension_point,
        )
        @ctx.puts(@ctx.message("script.create.change_directory_notice", project.title))
      rescue StandardError => e
        UI::ErrorHandler.pretty_print_and_raise(e, failed_op: @ctx.message("script.create.error.operation_failed"))
      end

      def self.help
        allowed_apis = Layers::Application::ExtensionPoints.available_types.map { |type| "{{cyan:#{type}}}" }
        allowed_languages = Layers::Application::ExtensionPoints.all_languages.map { |lang| "{{cyan:#{lang}}}" }
        ShopifyCLI::Context.message(
          "script.create.help",
          ShopifyCLI::TOOL_NAME,
          allowed_apis.join(", "),
          allowed_languages.join(", ")
        )
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
shopify-cli-2.18.1 lib/project_types/script/commands/create.rb
shopify-cli-2.18.0 lib/project_types/script/commands/create.rb
shopify-cli-2.17.0 lib/project_types/script/commands/create.rb
shopify-cli-2.16.1 lib/project_types/script/commands/create.rb
shopify-cli-2.16.0 lib/project_types/script/commands/create.rb
shopify-cli-2.15.6 lib/project_types/script/commands/create.rb
shopify-cli-2.15.5 lib/project_types/script/commands/create.rb
shopify-cli-2.15.4 lib/project_types/script/commands/create.rb
shopify-cli-2.15.3 lib/project_types/script/commands/create.rb
shopify-cli-2.15.2 lib/project_types/script/commands/create.rb
shopify-cli-2.15.1 lib/project_types/script/commands/create.rb
shopify-cli-2.15.0 lib/project_types/script/commands/create.rb
shopify-cli-2.14.0 lib/project_types/script/commands/create.rb
shopify-cli-2.13.0 lib/project_types/script/commands/create.rb