Module: Pvectl::Commands::SetResourceCommand Abstract
- Included in:
- SetContainer, SetNode, SetVm
- Defined in:
- lib/pvectl/commands/set_resource_command.rb
Overview
This module is abstract.
Include this module and implement template methods.
Shared functionality for resource set commands.
Template method pattern: provides common set workflow (config loading, key-value parsing, 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 set command.
-
#initialize(args, options, global_options) ⇒ Object
Initializes a set command.
Class Method Details
.included(base) ⇒ Object
Hook called when module is included.
39 40 41 |
# File 'lib/pvectl/commands/set_resource_command.rb', line 39 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#execute ⇒ Integer
Executes the set command.
57 58 59 60 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 |
# File 'lib/pvectl/commands/set_resource_command.rb', line 57 def execute resource_id = @args.first return usage_error("#{resource_id_label} is required") unless resource_id key_values = parse_key_values(@args[1..]) return usage_error("At least one key=value pair is required") if key_values.empty? load_config connection = Pvectl::Connection.new(@config) service = build_set_service(connection) result = service.execute(**execute_params(resource_id, key_values)) if result.nil? $stdout.puts "No changes detected." 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 a set command.
48 49 50 51 52 |
# File 'lib/pvectl/commands/set_resource_command.rb', line 48 def initialize(args, , ) @args = args @options = @global_options = end |