Class: Pvectl::Commands::Config::UseContext
- Inherits:
-
Object
- Object
- Pvectl::Commands::Config::UseContext
- Defined in:
- lib/pvectl/commands/config/use_context.rb
Overview
Handler for the ‘pvectl config use-context` command.
Switches the active context in the configuration file. The context name must exist in the configuration.
Class Method Summary collapse
-
.execute(context_name, global_options) ⇒ Integer
Executes the use-context command.
-
.register_subcommand(parent) ⇒ void
Registers the use-context subcommand.
Class Method Details
.execute(context_name, global_options) ⇒ Integer
Executes the use-context command.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pvectl/commands/config/use_context.rb', line 53 def self.execute(context_name, ) config_path = [:config] service = Pvectl::Config::Service.new service.load(config: config_path) service.use_context(context_name) puts "Switched to context \"#{context_name}\"." 0 rescue Pvectl::Config::ContextNotFoundError => e $stderr.puts "Error: #{e.}" ExitCodes::CONFIG_ERROR end |
.register_subcommand(parent) ⇒ void
This method returns an undefined value.
Registers the use-context subcommand.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pvectl/commands/config/use_context.rb', line 20 def self.register_subcommand(parent) parent.desc "Switch to a different context" parent.long_desc <<~HELP Switch the active context. The context determines which Proxmox cluster and credentials are used for subsequent commands. EXAMPLES Switch to production: $ pvectl config use-context production NOTES Changes are persisted to the config file immediately. Use PVECTL_CONTEXT env var for temporary overrides. HELP parent.command :"use-context" do |use_ctx| use_ctx.arg_name "CONTEXT_NAME" use_ctx.action do |, , args| if args.empty? $stderr.puts "Error: context name is required" exit ExitCodes::USAGE_ERROR end exit_code = execute(args[0], ) exit exit_code if exit_code != 0 end end end |