Sha256: 439f85ee8ab705562119162257e1d6582a13d4e4cc295143e3ea33fd7ee6f191

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Command
  class Delete < Base
    NAME = "delete"
    OPTIONS = [
      app_option(required: true),
      skip_confirm_option
    ].freeze
    DESCRIPTION = "Deletes the whole app (GVC with all workloads and all images)"
    LONG_DESCRIPTION = <<~DESC
      - Deletes the whole app (GVC with all workloads and all images)
      - Will ask for explicit user confirmation
    DESC

    def call
      return unless confirm_delete

      delete_gvc
      delete_images
    end

    private

    def confirm_delete
      return true if config.options[:yes]

      confirmed = Shell.confirm("Are you sure you want to delete '#{config.app}'?")
      return false unless confirmed

      progress.puts
      true
    end

    def delete_gvc
      return progress.puts("App '#{config.app}' does not exist.") if cp.fetch_gvc.nil?

      step("Deleting app '#{config.app}'") do
        cp.gvc_delete
      end
    end

    def delete_images
      images = cp.query_images["items"]
                 .filter_map { |item| item["name"] if item["name"].start_with?("#{config.app}:") }

      return progress.puts("No images to delete.") unless images.any?

      images.each do |image|
        step("Deleting image '#{image}'") do
          cp.image_delete(image)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cpl-1.1.2 lib/command/delete.rb
cpl-1.1.2.rc.0 lib/command/delete.rb
cpl-1.1.1 lib/command/delete.rb
cpl-1.1.0 lib/command/delete.rb