Sha256: 190691f89cca9d4ac133352cd2d7d0cb08bc706816e625c6c4310924632b655f

Contents?: true

Size: 1.82 KB

Versions: 8

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true
require "shopify_cli/theme/theme"
require "shopify_cli/theme/development_theme"

module Theme
  class Command
    class Delete < ShopifyCLI::SubCommand
      options do |parser, flags|
        parser.on("-d", "--development") { flags[:development] = true }
        parser.on("-a", "--show-all") { flags[:show_all] = true }
        parser.on("-f", "--force") { flags[:force] = true }
      end

      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"),
            exclude_roles: ["live"],
            include_foreign_developments: options.flags[:show_all],
          )
          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

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

      private

      def confirm?(theme)
        Forms::ConfirmStore.ask(
          @ctx,
          [],
          title: @ctx.message("theme.delete.confirm", theme.name, theme.shop),
          force: options.flags[:force],
        ).confirmed?
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shopify-cli-2.6.6 lib/project_types/theme/commands/delete.rb
shopify-cli-2.6.5 lib/project_types/theme/commands/delete.rb
shopify-cli-2.6.4 lib/project_types/theme/commands/delete.rb
shopify-cli-2.6.3 lib/project_types/theme/commands/delete.rb
shopify-cli-2.6.2 lib/project_types/theme/commands/delete.rb
shopify-cli-2.6.1 lib/project_types/theme/commands/delete.rb
shopify-cli-2.6.0 lib/project_types/theme/commands/delete.rb
shopify-cli-2.5.0 lib/project_types/theme/commands/delete.rb