class Arcanus::Command::Export
Public Instance Methods
execute()
click to toggle source
# 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
Private Instance Methods
extract_env_vars(hash, prefix = '')
click to toggle source
# File lib/arcanus/command/export.rb, line 41 def extract_env_vars(hash, prefix = '') output = [] hash.each do |key, value| if value.is_a?(Hash) output += extract_env_vars(value, "#{prefix}#{normalize_key(key)}_") else output << ["#{prefix}#{normalize_key(key)}", value] end end output end
normalize_key(key)
click to toggle source
# File lib/arcanus/command/export.rb, line 37 def normalize_key(key) key.upcase.tr('-', '_') end