Method: Tetra::Subcommand#ensure_dry_running

Defined in:
lib/tetra/ui/subcommand.rb

#ensure_dry_running(state, project) ⇒ Object

prints an error message and exits unless a dry-running condition is met. Conditions can be: :is_in_progress, :is_not_in_progress or :has_finished



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tetra/ui/subcommand.rb', line 51

def ensure_dry_running(state, project)
  dry_running = project.dry_running?
  has_finished = !project.version.nil?

  if (state == :is_in_progress && dry_running) ||
     (state == :is_not_in_progress && !dry_running) ||
     (state == :has_finished && !dry_running && has_finished)
    yield
  else
    if (state == :is_in_progress) ||
       (state == :has_finished && !dry_running && !has_finished)
      puts "Please start a dry-run first, use \"tetra dry-run\""
    elsif (state == :is_not_in_progress) ||
          (state == :has_finished && dry_running)
      puts "There is a dry-run in progress, please finish it (^D) or abort it (^C^D)"
    end
  end
end