bin/bagit in bagit-0.4.2 vs bin/bagit in bagit-0.4.3
- old
+ new
@@ -29,40 +29,38 @@
--tags List tag files.
--all List all data and tag files.
DOCOPT
- # Possible commands for bag-info write
- #
- # bagit new [--source-organization <org>] [--organization-address <org-addr>] [--contact-name <contact>]
- # [--contact-phone <phone>] [--contact-email <email>] [--external-description <ext-desc>]
- # [--external-identifier <ext-id>] [--group-identifier <group-id>] [--count <count>]
- # [--internal-sender-identifier <sender-id>] [--internal-sender-description <sender-desc>]
- # [--bag-info-entry <label> <value>] [-f <file>...] [-t <tagfile>...] BAGPATH
+# Possible commands for bag-info write
+#
+# bagit new [--source-organization <org>] [--organization-address <org-addr>] [--contact-name <contact>]
+# [--contact-phone <phone>] [--contact-email <email>] [--external-description <ext-desc>]
+# [--external-identifier <ext-id>] [--group-identifier <group-id>] [--count <count>]
+# [--internal-sender-identifier <sender-id>] [--internal-sender-description <sender-desc>]
+# [--bag-info-entry <label> <value>] [-f <file>...] [-t <tagfile>...] BAGPATH
begin
- opts = Docopt::docopt(doc, version: BagIt::VERSION)
+ opts = Docopt.docopt(doc, version: BagIt::VERSION)
- unless opts['validate']
- bag = BagIt::Bag.new(opts['BAGPATH'])
- end
+ bag = BagIt::Bag.new(opts['BAGPATH']) unless opts['validate']
#####################################
# commands that don't alter the bag #
#####################################
if opts['validate']
bag = BagIt::Bag.new(opts['BAGPATH'])
- if opts['--oxum']
- valid = bag.valid_oxum?
- else
- valid = bag.valid?
- end
+ valid = if opts['--oxum']
+ bag.valid_oxum?
+ else
+ bag.valid?
+ end
if valid
logger.info(valid)
else
- logger.error("#{valid}: #{bag.errors.full_messages.join(', ')}" )
+ logger.error("#{valid}: #{bag.errors.full_messages.join(', ')}")
end
# validation commands MUST NOT change manifest or bag-info files
exit
end
@@ -77,39 +75,38 @@
files.each { |f| puts f }
# quit here, too
exit
end
-
######################################
# commands that may cause data loss! #
######################################
- #TODO: implement delete for data and tag files; remove for tag files.
+ # 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 { |datafile|
+ # TODO: add files in nested directories
+ opts['-f'].each do |datafile|
begin
- if opts['add'] or opts['new']
+ if opts['add'] || opts['new']
bag.add_file(File.basename(datafile), datafile)
elsif opts['delete']
bag.remove_file(File.basename(datafile))
end
- rescue Exception => e
+ rescue StandardError => e
logger.error("Failed operation on bag file: #{e.message}")
end
- }
+ end
end
# handle adding tag files
unless opts['-t'].nil?
- #TODO: add files in nested directories
- opts['-t'].each { |tagfile|
+ # TODO: add files in nested directories
+ opts['-t'].each do |tagfile|
begin
- if opts['add'] or opts['new']
+ 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
@@ -118,23 +115,23 @@
elsif opts['delete']
bag.delete_tag_file(File.basename(tagfile))
elsif opts['remove']
bag.remove_tag_file(File.basename(tagfile))
end
- rescue Exception => e
+ rescue StandardError => e
logger.error("Failed operation on tag file: #{e.message}".red)
end
- }
+ end
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'] or not opts['-t'].nil?
+ bag.tagmanifest! if opts['-T'] || !opts['-t'].nil?
- unless opts['-a'].nil?
- bag.manifest!(algo: opts['<algo>'])
- else
+ if opts['-a'].nil?
bag.manifest!
+ else
+ bag.manifest!(algo: opts['<algo>'])
end
rescue Docopt::Exit => e
logger.error(e.message.red)
end