Class: Tomo::Plugin::Env::Tasks

Inherits:
TaskLibrary show all
Includes:
MonitorMixin
Defined in:
lib/tomo/plugin/env/tasks.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Methods inherited from TaskLibrary

#initialize

Constructor Details

This class inherits a constructor from Tomo::TaskLibrary

Instance Method Details

#setObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tomo/plugin/env/tasks.rb', line 44

def set
  return if settings[:run_args].empty?

  modify_env_file do |env|
    settings[:run_args].each do |arg|
      name, value = arg.split("=", 2)
      value ||= prompt_for(name)
      replace_entry(env, name, value)
    end
  end
end

#setupObject



15
16
17
18
# File 'lib/tomo/plugin/env/tasks.rb', line 15

def setup
  modify_bashrc
  update
end

#showObject



10
11
12
13
# File 'lib/tomo/plugin/env/tasks.rb', line 10

def show
  env = read_existing
  logger.info env.gsub(/^export /, "").strip
end

#unsetObject



56
57
58
59
60
61
62
63
64
# File 'lib/tomo/plugin/env/tasks.rb', line 56

def unset
  return if settings[:run_args].empty?

  modify_env_file do |env|
    settings[:run_args].each do |name|
      remove_entry(env, name)
    end
  end
end

#updateObject

rubocop:disable Metrics/MethodLength



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tomo/plugin/env/tasks.rb', line 20

def update # rubocop:disable Metrics/MethodLength
  return if settings[:env_vars].empty?

  modify_env_file do |env|
    settings[:env_vars].each do |name, value|
      case value
      when :prompt
        next if contains_entry?(env, name)

        value = prompt_for(name, message: <<~MSG)
          The remote host needs a value for the $#{name} environment variable.
          Please provide a value at the prompt.
        MSG
      when :generate_secret
        next if contains_entry?(env, name)

        value = SecureRandom.hex(64)
      end

      replace_entry(env, name, value)
    end
  end
end