Class: Pvectl::Commands::Config::GetContexts

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/commands/config/get_contexts.rb,
sig/pvectl/commands/config/get_contexts.rbs

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.

Examples:

Usage

pvectl config get-contexts
pvectl config get-contexts -o json
pvectl config get-contexts -o yaml
pvectl config get-contexts -o wide
pvectl config get-contexts --no-color

Class Method Summary collapse

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(global_options)
  config_path = global_options[: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: global_options[:output] || "table",
    color_flag: global_options[: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 "    List all contexts defined in the configuration file. The currently\n    active context is marked with an asterisk (*).\n\n    EXAMPLES\n      $ pvectl config get-contexts\n  HELP\n  parent.command :\"get-contexts\" do |get_ctx|\n    get_ctx.action do |global_options, _options, _args|\n      exit_code = execute(global_options)\n      exit exit_code if exit_code != 0\n    end\n  end\nend\n"