Sha256: 31d37c2b12a485e1ec5f6832d565e4949acd1042c4e5f921168c5696f1a1ec3a

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

require "uri"

module Node
  module Forms
    class Create < ShopifyCli::Form
      attr_accessor :name
      flag_arguments :title, :organization_id, :shop_domain, :type

      def ask
        self.title ||= CLI::UI::Prompt.ask(ctx.message("node.forms.create.app_name"))
        self.name = format_name
        self.type = ask_type
        res = ShopifyCli::Tasks::SelectOrgAndShop.call(ctx, organization_id: organization_id, shop_domain: shop_domain)
        self.organization_id = res[:organization_id]
        self.shop_domain = res[:shop_domain]
      end

      private

      def format_name
        name = title.downcase.split(" ").join("_")

        if name.include?("shopify")
          ctx.abort(ctx.message("node.forms.create.error.invalid_app_name"))
        end
        name
      end

      def ask_type
        if type.nil?
          return CLI::UI::Prompt.ask(ctx.message("node.forms.create.app_type.select")) do |handler|
            handler.option(ctx.message("node.forms.create.app_type.select_public")) { "public" }
            handler.option(ctx.message("node.forms.create.app_type.select_custom")) { "custom" }
          end
        end

        unless ShopifyCli::Tasks::CreateApiClient::VALID_APP_TYPES.include?(type)
          ctx.abort(ctx.message("node.forms.create.error.invalid_app_type", type))
        end
        ctx.puts(ctx.message("node.forms.create.app_type.selected", type))
        type
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
shopify-cli-2.4.0 lib/project_types/node/forms/create.rb
shopify-cli-2.3.0 lib/project_types/node/forms/create.rb
shopify-cli-2.2.2 lib/project_types/node/forms/create.rb
shopify-cli-2.2.1 lib/project_types/node/forms/create.rb
shopify-cli-2.2.0 lib/project_types/node/forms/create.rb
shopify-cli-2.1.0 lib/project_types/node/forms/create.rb
shopify-cli-2.0.2 lib/project_types/node/forms/create.rb
shopify-cli-2.0.1 lib/project_types/node/forms/create.rb
shopify-cli-2.0.0 lib/project_types/node/forms/create.rb
shopify-cli-1.14.0 lib/project_types/node/forms/create.rb
shopify-cli-1.13.1 lib/project_types/node/forms/create.rb
shopify-cli-1.13.0 lib/project_types/node/forms/create.rb
shopify-cli-1.12.0 lib/project_types/node/forms/create.rb
shopify-cli-1.11.0 lib/project_types/node/forms/create.rb
shopify-cli-1.10.0 lib/project_types/node/forms/create.rb
shopify-cli-1.9.1 lib/project_types/node/forms/create.rb
shopify-cli-1.9.0 lib/project_types/node/forms/create.rb
shopify-cli-1.8.0 lib/project_types/node/forms/create.rb