Sha256: 4a72edf683091f8764ae3b65c3ed97b78425f79252952742d82a8371c6b888f1

Contents?: true

Size: 1.54 KB

Versions: 20

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module Extension
  module Commands
    class Create < ShopifyCli::SubCommand
      options do |parser, flags|
        parser.on('--name=NAME') { |name| flags[:name] = name }
        parser.on('--type=TYPE') { |type| flags[:type] = type.upcase }
      end

      def call(args, _)
        with_create_form(args) do |form|
          if Dir.exist?(form.directory_name)
            @ctx.abort(@ctx.message('create.errors.directory_exists', form.directory_name))
          end

          if form.type.create(form.directory_name, @ctx)
            ExtensionProject.write_cli_file(context: @ctx, type: form.type.identifier)
            ExtensionProject.write_env_file(context: @ctx, title: form.name)

            @ctx.puts(@ctx.message('create.ready_to_start', form.directory_name, form.name))
            @ctx.puts(@ctx.message('create.learn_more', form.type.name))
          else
            @ctx.puts(@ctx.message('create.try_again'))
          end
        end
      end

      def self.help
        <<~HELP
          Create a new app extension.
            Usage: {{command:#{ShopifyCli::TOOL_NAME} create extension <name>}}
            Options:
              {{command:--type=TYPE}} The type of extension you would like to create.
              {{command:--name=NAME}} The name of your extension (50 characters).”
        HELP
      end

      private

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

        yield form
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
shopify-cli-1.6.0 lib/project_types/extension/commands/create.rb
shopify-cli-1.5.0 lib/project_types/extension/commands/create.rb
shopify-cli-1.4.1 lib/project_types/extension/commands/create.rb
shopify-cli-1.4.0 lib/project_types/extension/commands/create.rb
shopify-cli-1.3.1 lib/project_types/extension/commands/create.rb
shopify-cli-1.3.0 lib/project_types/extension/commands/create.rb
shopify-cli-1.2.0 lib/project_types/extension/commands/create.rb
shopify-cli-1.1.2 lib/project_types/extension/commands/create.rb
shopify-cli-1.1.1 lib/project_types/extension/commands/create.rb
shopify-cli-1.1.0 lib/project_types/extension/commands/create.rb
shopify-cli-1.0.5 lib/project_types/extension/commands/create.rb
shopify-cli-1.0.4 lib/project_types/extension/commands/create.rb
shopify-cli-1.0.3 lib/project_types/extension/commands/create.rb
shopify-cli-1.0.2 lib/project_types/extension/commands/create.rb
shopify-cli-1.0.1 lib/project_types/extension/commands/create.rb
shopify-cli-1.0.0 lib/project_types/extension/commands/create.rb
shopify-cli-0.9.3 lib/project_types/extension/commands/create.rb
shopify-cli-0.9.2 lib/project_types/extension/commands/create.rb
shopify-cli-0.9.1 lib/project_types/extension/commands/create.rb
shopify-cli-0.9.0 lib/project_types/extension/commands/create.rb