Class: Pvectl::Commands::Config::GetContexts
- Inherits:
-
Object
- Object
- Pvectl::Commands::Config::GetContexts
- Defined in:
- lib/pvectl/commands/config/get_contexts.rb
Overview
Handler for the ‘pvectl config get-contexts` command.
Lists all contexts defined in the configuration file with an indicator showing which context is currently active. Uses the unified OutputHelper for formatting output.
Class Method Summary collapse
-
.execute(global_options) ⇒ Integer
Executes the get-contexts command.
-
.register_subcommand(parent) ⇒ void
Registers the get-contexts subcommand.
Class Method Details
.execute(global_options) ⇒ Integer
Executes the get-contexts command.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pvectl/commands/config/get_contexts.rb', line 45 def self.execute() config_path = [:config] service = Pvectl::Config::Service.new service.load(config: config_path) contexts = service.contexts current_context_name = service.current_context_name presenter = Pvectl::Presenters::Config::Context.new Pvectl::Formatters::OutputHelper.print( data: contexts, presenter: presenter, format: [:output] || "table", color_flag: [:color], current_context: current_context_name ) 0 end |
.register_subcommand(parent) ⇒ void
This method returns an undefined value.
Registers the get-contexts subcommand.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pvectl/commands/config/get_contexts.rb', line 24 def self.register_subcommand(parent) parent.desc "List all available contexts" parent.long_desc <<~HELP List all contexts defined in the configuration file. The currently active context is marked with an asterisk (*). EXAMPLES $ pvectl config get-contexts HELP parent.command :"get-contexts" do |get_ctx| get_ctx.action do |, , _args| exit_code = execute() exit exit_code if exit_code != 0 end end end |