Class: Theme::Command::Delete

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

Instance Attribute Summary

Attributes inherited from ShopifyCLI::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

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



54
55
56
# File 'lib/project_types/theme/commands/delete.rb', line 54

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

Instance Method Details

#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