Module: EnvLint::Capistrano

Defined in:
lib/env_lint/capistrano.rb

Class Method Summary collapse

Class Method Details

.load_into(config, formatter) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
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
# File 'lib/env_lint/capistrano.rb', line 6

def self.load_into(config, formatter)
  config.load do
    set(:env_definition_file) { '.env.example' }
    set(:env_probe_command) { "su - #{application_user} -c 'export'" }

    namespace :env do
      desc 'Check that every non optional ENV variable is defined.'
      task :lint do
        begin
          EnvLint.verify_export_output(env_definition_file, capture("#{sudo} #{env_probe_command}"))
          formatter.ok('env looks ok')
        rescue EnvLint::MissingVariables => e
          formatter.missing_variables(e.dot_env_file, e.missing_variables)
          abort
        rescue EnvLint::Error => e
          formatter.error(e.message)
          abort
        end
      end

      desc 'Lint args passed to command.'
      task :lint_args do
        begin
          EnvLint.verify_args(env_definition_file, env_args)
        rescue EnvLint::UnknownVariables => e
          formatter.unknown_variables(e.dot_env_file, e.unknown_variables)
          abort
        rescue EnvLint::Error => e
          formatter.error(e.message)
          abort
        end
      end

      def env_args
        ARGV[1..-1]
      end
    end
  end
end