Class: Ddenv::Commands::Up

Inherits:
Ddenv::Command show all
Defined in:
lib/ddenv/commands/up.rb

Instance Method Summary collapse

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ddenv/commands/up.rb', line 6

def call
  config = Ddenv::Config.read_from_file("ddenv.yaml")

  all_goals = config.goals.flat_map(&:with_pre_and_post_goals).uniq

  max_message_size = all_goals.map { _1.message.size }.max

  all_goals.each do |goal|
    spinner = TTY::Spinner.new("[:spinner] :message   :title")
    spinner.update(message: format("%-#{max_message_size}s", goal.message))
    spinner.update(title: "checking")
    spinner.auto_spin

    if goal.achieved?
      spinner.update(title: "done (previously achieved)")
    else
      spinner.update(title: "working...")
      goal.achieve
      spinner.update(title: "done (newly achieved)")
    end
    spinner.success
  end
end