Module: Pvectl::Commands::IrreversibleCommand

Included in:
DeleteCommand, TemplateCommand
Defined in:
lib/pvectl/commands/irreversible_command.rb

Overview

Shared functionality for irreversible batch commands (delete, template).

Provides the generic flow: resolve resources → confirm → execute → format results. Submodules override hooks to customize behavior per operation.

Examples:

Including in an operation-specific module

module TemplateCommand
  include IrreversibleCommand

  def self.included(base)
    base.extend(IrreversibleCommand::ClassMethods)
  end
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Hook called when module is included.

Parameters:

  • base (Module)

    the module or class including this module



37
38
39
# File 'lib/pvectl/commands/irreversible_command.rb', line 37

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#executeInteger

Executes the command.

Returns:

  • (Integer)

    exit code



57
58
59
60
61
62
63
64
65
66
# File 'lib/pvectl/commands/irreversible_command.rb', line 57

def execute
  return usage_error("Resource type required (#{supported_types.join(', ')})") unless @resource_type
  return usage_error("Unsupported resource: #{@resource_type}") unless supported_resource?

  if @resource_ids.empty? && !@options[:all] && selector_strings.empty?
    return usage_error("VMID, --all, or -l selector required")
  end

  perform_operation
end

#initialize(resource_type, resource_ids, options, global_options) ⇒ Object

Initializes an irreversible command.

Parameters:

  • resource_type (String, nil)

    resource type (vm, container)

  • resource_ids (Array<String>, String, nil)

    resource identifiers

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options



47
48
49
50
51
52
# File 'lib/pvectl/commands/irreversible_command.rb', line 47

def initialize(resource_type, resource_ids, options, global_options)
  @resource_type = resource_type
  @resource_ids = Array(resource_ids).compact
  @options = options
  @global_options = global_options
end