summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2019-01-26 10:57:38 +0000
committerPaul Bütow <pbuetow@mimecast.com>2019-01-26 10:57:38 +0000
commit9b76729361b9e212aaf1f3c64c2d12bbd74ec656 (patch)
treebb6ccdf6ec3c8caeaeee30141799311479f589ad
parent030e014769f6423f901f33f23a3e949b76aa3e42 (diff)
fix add
-rwxr-xr-xgeheim.rb28
1 files 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'