bin/bagit in bagit-0.4.3 vs bin/bagit in bagit-0.4.4
- old
+ new
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
require 'bagit'
require 'docopt'
require 'logger'
-require 'pry'
logger = Logger.new(STDOUT)
doc = <<DOCOPT
BagIt.
@@ -82,46 +82,36 @@
######################################
# TODO: implement delete for data and tag files; remove for tag files.
# handle add/delete bag data files
- unless opts['-f'].nil?
- # TODO: add files in nested directories
- opts['-f'].each do |datafile|
- begin
- if opts['add'] || opts['new']
- bag.add_file(File.basename(datafile), datafile)
- elsif opts['delete']
- bag.remove_file(File.basename(datafile))
- end
- rescue StandardError => e
- logger.error("Failed operation on bag file: #{e.message}")
- end
+ opts['-f']&.each do |datafile|
+ if opts['add'] || opts['new']
+ bag.add_file(File.basename(datafile), datafile)
+ elsif opts['delete']
+ bag.remove_file(File.basename(datafile))
end
+ rescue StandardError => e
+ logger.error("Failed operation on bag file: #{e.message}")
end
# handle adding tag files
- unless opts['-t'].nil?
- # TODO: add files in nested directories
- opts['-t'].each do |tagfile|
- begin
- if opts['add'] || opts['new']
- # if it does, try to manifest it
- if File.exist?(File.join(bag.bag_dir, File.basename(tagfile)))
- bag.add_tag_file(tagfile)
- # otherwise, add it
- else
- bag.add_tag_file(File.basename(tagfile), tagfile)
- end
- elsif opts['delete']
- bag.delete_tag_file(File.basename(tagfile))
- elsif opts['remove']
- bag.remove_tag_file(File.basename(tagfile))
- end
- rescue StandardError => e
- logger.error("Failed operation on tag file: #{e.message}".red)
+ opts['-t']&.each do |tagfile|
+ if opts['add'] || opts['new']
+ # if it does, try to manifest it
+ if File.exist?(File.join(bag.bag_dir, File.basename(tagfile)))
+ bag.add_tag_file(tagfile)
+ # otherwise, add it
+ else
+ bag.add_tag_file(File.basename(tagfile), tagfile)
end
+ elsif opts['delete']
+ bag.delete_tag_file(File.basename(tagfile))
+ elsif opts['remove']
+ bag.remove_tag_file(File.basename(tagfile))
end
+ rescue StandardError => e
+ logger.error("Failed operation on tag file: #{e.message}".red)
end
# if we haven't quit yet, we need to re-manifest
# only do tags if tag files have been explictly added/removed or it is explictly called
bag.tagmanifest! if opts['-T'] || !opts['-t'].nil?