Class: Nvoi::Cli::Onboard::Steps::App

Inherits:
Object
  • Object
show all
Includes:
Ui
Defined in:
lib/nvoi/cli/onboard/steps/app.rb

Overview

Single app form - used for add and edit

Constant Summary

Constants included from Ui

Ui::MAX_RETRIES

Instance Method Summary collapse

Methods included from Ui

#box, #error, #output, #prompt_with_retry, #section, #success, #table, #with_spinner

Constructor Details

#initialize(prompt, test_mode: false) ⇒ App

Returns a new instance of App.



11
12
13
14
# File 'lib/nvoi/cli/onboard/steps/app.rb', line 11

def initialize(prompt, test_mode: false)
  @prompt = prompt
  @test_mode = test_mode
end

Instance Method Details

#call(existing_name: nil, existing: nil, zones: [], cloudflare_client: nil) ⇒ Object

Returns [name, config] tuple



17
18
19
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
46
47
48
# File 'lib/nvoi/cli/onboard/steps/app.rb', line 17

def call(existing_name: nil, existing: nil, zones: [], cloudflare_client: nil)
  @zones = zones
  @cloudflare_client = cloudflare_client

  name = @prompt.ask("App name:", default: existing_name) { |q| q.required true }

  command = prompt_optional("Run command", existing&.dig("command"),
    placeholder: "leave blank for Docker entrypoint")

  port = prompt_optional("Port", existing&.dig("port")&.to_s,
    placeholder: "leave blank for background workers")
  port = port.to_i if port && !port.blank?

  config = { "servers" => existing&.dig("servers") || ["main"] }
  config["command"] = command unless command.blank?
  config["port"] = port if port && port.to_i > 0

  # Domain selection only if port is set and cloudflare configured
  if port && port.to_i > 0 && @zones.any?
    domain, subdomain = prompt_domain_selection
    if domain
      config["domain"] = domain
      config["subdomain"] = subdomain unless subdomain.blank?
    end
  end

  pre_run = prompt_optional("Pre-run command", existing&.dig("pre_run_command"),
    placeholder: "e.g. migrations")
  config["pre_run_command"] = pre_run unless pre_run.blank?

  [name, config]
end