Class: PerfectWorld::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/perfect_world/cli.rb

Constant Summary collapse

CONFIG =

Default config.

{
  'clipboard' => false,
  'database' => File.expand_path('~/.pwm.yml.gpg'),
  'force' => false,
  'length' => 64
}

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Cli

Sets the config.



21
22
23
24
# File 'lib/perfect_world/cli.rb', line 21

def initialize(config = {})
  @config = CONFIG.merge(config)
  GPGME::Engine.home_dir = @config['gpgdir'] if @config.key?('gpgdir')
end

Instance Method Details

#run(commands) ⇒ Object

Loads the database and executes the provided commands.



27
28
29
30
31
# File 'lib/perfect_world/cli.rb', line 27

def run(commands)
  DB.open(@config.fetch('database'), @config['owner']) do |db|
    commands.each { |cmd, arg| send(cmd, db, arg) }
  end
end