Sha256: ebb91c41d8e22437a3b236100c16656688a2a0fb21c387d020fbc7dd004e18e4

Contents?: true

Size: 1.1 KB

Versions: 17

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Extension
  module Forms
    class Register < ShopifyCli::Form
      flag_arguments :api_key

      attr_reader :app

      def ask
        self.app = ask_app
      end

      private

      attr_writer :app

      def ask_app
        if !api_key.nil?
          found_app = Tasks::GetApp.call(context: ctx, api_key: api_key)
          ctx.abort(ctx.message('register.invalid_api_key', api_key)) if found_app.nil?
          found_app
        else
          apps = load_apps
          CLI::UI::Prompt.ask(ctx.message('register.ask_app')) do |handler|
            apps.each do |app|
              handler.option("#{app.title} by #{app.business_name}") { app }
            end
          end
        end
      end

      def load_apps
        ctx.puts(@ctx.message('register.loading_apps'))
        apps = Tasks::GetApps.call(context: ctx)

        apps.empty? ? abort_no_apps : apps
      end

      def abort_no_apps
        ctx.puts(@ctx.message('register.no_apps'))
        ctx.puts(@ctx.message('register.learn_about_apps'))
        raise ShopifyCli::AbortSilent
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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