Class: Arcanus::Command::Export

Inherits:
Base
  • Object
show all
Includes:
Shared::EnsureKey
Defined in:
lib/arcanus/command/export.rb

Instance Method Summary collapse

Methods included from Shared::EnsureKey

#ensure_key_unlocked

Methods inherited from Base

description, #execute_command, from_arguments, #initialize, #run, short_name

Methods included from Utils

camel_case, deep_dup, snake_case

Constructor Details

This class inherits a constructor from Arcanus::Command::Base

Instance Method Details

#executeObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/arcanus/command/export.rb', line 11

def execute
  ensure_key_unlocked

  key = Arcanus::Key.from_file(repo.unlocked_key_path)
  chest = Arcanus::Chest.new(key: key, chest_file_path: repo.chest_file_path)

  env_vars = extract_env_vars(chest.to_hash)

  output_lines =
    case arguments[1]
    when nil
      env_vars.map { |var, val| "#{var}=#{val.to_s.shellescape}" }
    when '--shell'
      env_vars.map { |var, val| "export #{var}=#{val.to_s.shellescape}" }
    when '--docker'
      # Docker env files don't need any escaping
      env_vars.map { |var, val| "#{var}=#{val}" }
    else
      raise Arcanus::Errors::UsageError, "Unknown export flag #{arguments[1]}"
    end

  ui.print output_lines.join("\n")
end