Sha256: ae2bd91bf1c44b25b2850edfdb8899e71b25d4874d9ab1df66809cb89ba8fad2

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true
require "shopify-cli/theme/theme"
require "shopify-cli/theme/ignore_filter"
require "shopify-cli/theme/syncer"

module Theme
  class Command
    class Pull < ShopifyCli::SubCommand
      options do |parser, flags|
        parser.on("-n", "--nodelete") { flags[:nodelete] = true }
        parser.on("-i", "--themeid=ID") { |theme_id| flags[:theme_id] = theme_id }
      end

      def call(args, _name)
        root = args.first || "."
        delete = !options.flags[:nodelete]

        theme = if (theme_id = options.flags[:theme_id])
          ShopifyCli::Theme::Theme.new(@ctx, root: root, id: theme_id)
        else
          form = Forms::Select.ask(
            @ctx,
            [],
            title: @ctx.message("theme.pull.select"),
            root: root,
          )
          return unless form
          form.theme
        end

        ignore_filter = ShopifyCli::Theme::IgnoreFilter.from_path(root)
        syncer = ShopifyCli::Theme::Syncer.new(@ctx, theme: theme, ignore_filter: ignore_filter)
        begin
          syncer.start_threads
          CLI::UI::Frame.open(@ctx.message("theme.pull.pulling", theme.name, theme.id, theme.shop)) do
            UI::SyncProgressBar.new(syncer).progress(:download_theme!, delete: delete)
          end
          @ctx.done(@ctx.message("theme.pull.done"))
        rescue ShopifyCli::API::APIRequestNotFoundError
          @ctx.abort(@ctx.message("theme.pull.theme_not_found", theme.id))
        ensure
          syncer.shutdown
        end
      end

      def self.help
        ShopifyCli::Context.message("theme.pull.help", ShopifyCli::TOOL_NAME, ShopifyCli::TOOL_NAME)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shopify-cli-2.2.2 lib/project_types/theme/commands/pull.rb
shopify-cli-2.2.1 lib/project_types/theme/commands/pull.rb
shopify-cli-2.2.0 lib/project_types/theme/commands/pull.rb
shopify-cli-2.1.0 lib/project_types/theme/commands/pull.rb
shopify-cli-2.0.2 lib/project_types/theme/commands/pull.rb
shopify-cli-2.0.1 lib/project_types/theme/commands/pull.rb
shopify-cli-2.0.0 lib/project_types/theme/commands/pull.rb