Sha256: 62100b8e4015f2ca74f7a5fb3caf34bf7e6413ad0dbc8eaeac38eee991313799

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 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 = <<~HEREDOC
      - Deletes the whole app (GVC with all workloads and all images)
      - Will ask for explicit user confirmation
    HEREDOC

    def call
      return unless confirm_delete

      delete_gvc
      delete_images
    end

    private

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

      confirmed = thor_shell.yes?("Are you sure you want to delete '#{config.app}' (y/n)?")
      return false unless confirmed

      progress.puts
      true
    end

    def delete_gvc
      progress.puts "- Deleting gvc:"

      return progress.puts "none" unless cp.gvc_get

      cp.gvc_delete
      progress.puts config.app
    end

    def delete_images
      progress.puts "- Deleting image(s):"

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

      return progress.puts "none" unless images

      images.each do |image|
        cp.image_delete(image)
        progress.puts image
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cpl-0.2.0 lib/command/delete.rb