Class: Theme::Command::Pull

Inherits:
ShopifyCLI::Command::SubCommand show all
Includes:
Common::RootHelper, Common::ShopHelper
Defined in:
lib/project_types/theme/commands/pull.rb

Instance Attribute Summary

Attributes inherited from ShopifyCLI::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::RootHelper

#exist_and_not_empty?, #root_value, #valid_theme_directory?

Methods included from Common::ShopHelper

#shop

Methods inherited from ShopifyCLI::Command::SubCommand

call

Methods inherited from ShopifyCLI::Command

call, call_help, check_node_version, check_ruby_version, check_version, #initialize, options, prerequisite_task, recommend_default_node_range, recommend_default_ruby_range, recommend_node, recommend_ruby, run_prerequisites, subcommand, subcommand_registry

Methods included from ShopifyCLI::Feature::Set

#hidden?, #hidden_feature

Constructor Details

This class inherits a constructor from ShopifyCLI::Command

Class Method Details

.helpObject



78
79
80
# File 'lib/project_types/theme/commands/pull.rb', line 78

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

Instance Method Details

#call(_args, name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/project_types/theme/commands/pull.rb', line 43

def call(_args, name)
  root = root_value(options, name)
  return if exist_and_not_empty?(root) && !valid_theme_directory?(root)

  development_theme_id = options.flags[:development_theme_id]
  ShopifyCLI::DB.set(development_theme_id: development_theme_id) unless development_theme_id.nil?

  delete = !options.flags[:nodelete]
  theme = find_theme(root, **options.flags)
  return if theme.nil?

  include_filter = ShopifyCLI::Theme::IncludeFilter.new(root, options.flags[:includes])
  ignore_filter = ShopifyCLI::Theme::IgnoreFilter.from_path(root)
  ignore_filter.add_patterns(options.flags[:ignores]) if options.flags[:ignores]

  syncer = ShopifyCLI::Theme::Syncer.new(@ctx, theme: theme,
    include_filter: include_filter,
    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
    if syncer.has_any_error?
      @ctx.warn(@ctx.message("theme.pull.done_with_errors"))
    else
      @ctx.done(@ctx.message("theme.pull.done"))
    end
  rescue ShopifyCLI::API::APIRequestNotFoundError
    @ctx.abort(@ctx.message("theme.pull.theme_not_found", "##{theme.id}"))
  ensure
    syncer.shutdown
  end
end