Class: Pvectl::Config::Wizard

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/config/wizard.rb

Overview

Interactive configuration wizard for first-time setup.

Wizard guides users through initial configuration by prompting for server URL, authentication credentials, and SSL settings. It only runs when stdin is a TTY (not in pipes or scripts).

Examples:

Checking if wizard is available

if Wizard.available?
  wizard = Wizard.new
  config = wizard.run
end

Using custom prompt (for testing)

wizard = Wizard.new(prompt: mock_prompt)
config = wizard.run

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt: nil) ⇒ Wizard

Creates a new Wizard instance.

Parameters:

  • prompt (Object, nil) (defaults to: nil)

    prompt object for user input (default: built-in)



32
33
34
# File 'lib/pvectl/config/wizard.rb', line 32

def initialize(prompt: nil)
  @prompt = prompt || create_default_prompt
end

Class Method Details

.available?Boolean

Checks if the wizard can run (stdin is a TTY).

Returns:

  • (Boolean)

    true if stdin is a TTY



25
26
27
# File 'lib/pvectl/config/wizard.rb', line 25

def self.available?
  $stdin.tty?
end

Instance Method Details

#runHash

Runs the interactive wizard and returns configuration.

Returns:

  • (Hash)

    configuration hash ready for YAML serialization



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pvectl/config/wizard.rb', line 39

def run
  server = prompt_server
  verify_ssl = prompt_ssl
  auth_type = prompt_auth_type
  credentials = prompt_credentials(auth_type)
  context_name = prompt_context_name

  build_config(
    server: server,
    verify_ssl: verify_ssl,
    auth_type: auth_type,
    credentials: credentials,
    context_name: context_name
  )
end