Method: Theme::Command::Delete#call

Defined in:
lib/project_types/theme/commands/delete.rb

#call(args, _name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/project_types/theme/commands/delete.rb', line 19

def call(args, _name)
  themes = if options.flags[:development]
    [ShopifyCLI::Theme::DevelopmentTheme.new(@ctx)]
  elsif args.any?
    args.map { |id| ShopifyCLI::Theme::Theme.new(@ctx, id: id) }
  else
    form = Forms::Select.ask(
      @ctx,
      [],
      title: @ctx.message("theme.delete.select", shop),
      exclude_roles: ["live"],
      include_foreign_developments: options.flags[:show_all],
      cmd: :delete
    )
    return unless form
    [form.theme]
  end

  deleted = 0
  themes.each do |theme|
    if theme.live?
      @ctx.puts(@ctx.message("theme.delete.live", theme.id))
      next
    elsif !confirm?(theme)
      next
    end
    theme.delete
    deleted += 1
  rescue ShopifyCLI::API::APIRequestNotFoundError
    @ctx.puts(@ctx.message("theme.delete.not_found", theme.id))
  end

  @ctx.done(@ctx.message("theme.delete.done", deleted))
end