Sha256: a2bce160d3b613ea5bc8edde438eeb1a051fe933b202ca87bfc8ee26fd292631

Contents?: true

Size: 1.82 KB

Versions: 9

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

9 entries across 9 versions & 1 rubygems

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