Module: Orchparty::Plugin::Env

Defined in:
lib/orchparty/plugins/env.rb

Class Method Summary collapse

Class Method Details

.define_flags(c) ⇒ Object



11
12
13
14
15
# File 'lib/orchparty/plugins/env.rb', line 11

def self.define_flags(c)
  c.flag %i[output o], desc: 'Set the output file'
  c.flag %i[service s], desc: 'Set the service to generate environment variables from.'
  c.flag %i[seperator sep], desc: 'How to join the environment variables', default_value: '\\n'
end

.descObject



7
8
9
# File 'lib/orchparty/plugins/env.rb', line 7

def self.desc
  'generate environment variables'
end

.env_output(application, options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/orchparty/plugins/env.rb', line 26

def self.env_output(application, options)
  services = if options[:service]
               [application.services[options[:service]]]
             else
               application.services.values
             end

  options[:sep] = "\n" if options[:sep] == '\\n'

  envs = services.map(&:environment).compact.inject({}) { |a, v| a.merge(v) }
  envs.map { |k, v| "#{k}=#{v.is_a?(String) ? v.shellescape : v}" }.join(options[:sep])
end

.generate(ast, options) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/orchparty/plugins/env.rb', line 17

def self.generate(ast, options)
  output = env_output(ast, options)
  if options[:output]
    File.write(options[:output], output)
  else
    print output
  end
end