Sha256: 37916526e31a8b16cfc8c551ec829b3d777fdd4ba41b25b16ce7c78a8571e95a

Contents?: true

Size: 997 Bytes

Versions: 4

Compression:

Stored size: 997 Bytes

Contents

require 'donjon/commands/base'

module Donjon
  module Commands
    Base.class_eval do
      desc 'config:set KEY=VALUE ...', 'Encrypts KEY and VALUE in the vault'
      decl 'config:set'

      desc 'config:get KEY...', 'Decrypts the value for KEY from the vault'
      decl 'config:get'
      
      desc 'config:mget [REGEXP]', 'Decrypts multiple keys (all readable by default)'
      decl 'config:mget'
      
      private
      
      def config_set(*keyvals)
        keyvals.each do |keyval|
          m = /([^=]*)=(.*)/.match(keyval)
          key = m[1]
          value = m[2]
          database[key] = value
        end
      end

      def config_get(*keys)
        keys.each do |key|
          puts "#{key}: #{database[key]}"
        end
      end

      def config_mget(regexp = nil)
        regexp = Regexp.new(regexp) if regexp
        database.each do |key, value|
          next if regexp && regexp !~ key
          puts "#{key}: #{value}"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
donjon-0.0.4 lib/donjon/commands/config.rb
donjon-0.0.3 lib/donjon/commands/config.rb
donjon-0.0.2 lib/donjon/commands/config.rb
donjon-0.0.1 lib/donjon/commands/config.rb