From 9b76729361b9e212aaf1f3c64c2d12bbd74ec656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= Date: Sat, 26 Jan 2019 10:57:38 +0000 Subject: fix add --- geheim.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/geheim.rb b/geheim.rb index 3a023a2..9815eda 100755 --- a/geheim.rb +++ b/geheim.rb @@ -291,25 +291,33 @@ class Geheim end end - def add(description: nil, file: nil, dest_dir: nil, force: false) + def add(description:) + hash = hash_path(description) + + print "Data: " + data = $stdin.gets.chomp + + index = Index.new(index_file: "#{hash}.index", description: description) + data = index.get_data(data: data) + + data.commit + index.commit + end + + def import(description: nil, file: nil, dest_dir: nil, force: false) src_path = file.gsub("//", "/") dest_path = if dest_dir.nil? src_path - else - if dest_dir.include?(".") + elsif dest_dir.include?(".") dest_dir - else + else "#{dest_dir}/#{File.basename(file)}".gsub("//", "/") - end end hash = hash_path(dest_path) - if file.nil? - print "Data: " - data = $stdin.gets.chomp - elsif !File.exists?(src_path) + if !File.exists?(src_path) puts "ERROR: #{file} does not exist!" exit(3) else @@ -453,7 +461,7 @@ class CLI when 'add' geheim.add(description: argv[1]) when 'import' - geheim.add(file: argv[1], dest_dir: argv[2], force: !argv[3].nil?) + geheim.import(file: argv[1], dest_dir: argv[2], force: !argv[3].nil?) when 'import_r' geheim.import_recursive(directory: argv[1], dest_dir: argv[2]) when 'rm' -- cgit v1.2.3