Module: Pvectl::Commands::EditResourceCommand Abstract
- Included in:
- EditContainer, EditNode, EditVm
- Defined in:
- lib/pvectl/commands/edit_resource_command.rb
Overview
This module is abstract.
Include this module and implement template methods.
Shared functionality for resource edit commands.
Template method pattern: provides common edit workflow (config loading, editor session, diff display, dry-run) while specialization classes define resource-specific hooks.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Hook called when module is included.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the edit command.
-
#initialize(args, options, global_options) ⇒ Object
Initializes an edit command.
Class Method Details
.included(base) ⇒ Object
Hook called when module is included.
39 40 41 |
# File 'lib/pvectl/commands/edit_resource_command.rb', line 39 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#execute ⇒ Integer
Executes the edit command.
Loads configuration, builds the edit service, and runs it. Handles cancelled edits, successful updates with diff display, dry-run mode, and errors.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pvectl/commands/edit_resource_command.rb', line 61 def execute resource_id = @args.first return usage_error("#{resource_id_label} is required") unless resource_id load_config connection = Pvectl::Connection.new(@config) service = build_edit_service(connection) result = service.execute(**execute_params(resource_id)) if result.nil? $stdout.puts "Edit cancelled, no changes made." return ExitCodes::SUCCESS end if result.successful? display_diff(result) if @options[:"dry-run"] $stdout.puts "(dry-run mode — no changes applied)" else $stdout.puts "#{resource_label} #{resource_id} updated successfully." end ExitCodes::SUCCESS else $stderr.puts "Error: #{result.error}" ExitCodes::GENERAL_ERROR end rescue Pvectl::Config::ConfigNotFoundError, Pvectl::Config::InvalidConfigError, Pvectl::Config::ContextNotFoundError, Pvectl::Config::ClusterNotFoundError, Pvectl::Config::UserNotFoundError raise rescue StandardError => e $stderr.puts "Error: #{e.}" ExitCodes::GENERAL_ERROR end |
#initialize(args, options, global_options) ⇒ Object
Initializes an edit command.
48 49 50 51 52 |
# File 'lib/pvectl/commands/edit_resource_command.rb', line 48 def initialize(args, , ) @args = args @options = @global_options = end |