Class: EncrApp
Constant Summary
Constants included from LEnc
LEnc::KEY_LEN_MAX, LEnc::KEY_LEN_MIN
Instance Method Summary collapse
Instance Method Details
#run(argv = ARGV) ⇒ 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 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lenc/encr.rb', line 6 def run(argv = ARGV) req 'trollop' p = Trollop::Parser.new do opt :init, "create new singular repository" opt :orignames, "(with --init) leave filenames unencrypted" opt :encrypt, "encrypt files (default operation)" opt :decrypt, "decrypt files" opt :key, "encryption key", :type => :string opt :verbose,"verbose operation" opt :where, "specify source directory (default = current directory)", :type => :strings opt :quiet, "quiet operation" opt :dryrun, "show which files will be modified, but make no changes" end = Trollop::with_standard_exception_handling p do p.parse argv end v = 0 v = -1 if [:quiet] v = 1 if [:verbose] nOpt = 0 nOpt += 1 if [:init] nOpt += 1 if [:encrypt] nOpt += 1 if [:decrypt] p.die("Only one operation can be performed at a time.",nil) if nOpt > 1 r = Repo.new(:dryrun => [:dryrun], :verbosity => v) key = [:key] begin if [:init] r.create([:where], key, nil, [:orignames]) elsif [:decrypt] r.open([:where],key) r.perform_decrypt else r.open([:where],key) r.perform_encrypt end r.close() rescue Exception =>e puts("\nProblem encountered: #{e.message}") end end |