Sha256: 6b235acebc0920c95c26e143bd57f0913b1a3b465756fbe434b252a123d4d63c
Contents?: true
Size: 1.91 KB
Versions: 11
Compression:
Stored size: 1.91 KB
Contents
module MDQT class CLI require 'mdqt/cli/base' class Rename < Base def run options.validate = true advise_on_xml_signing_support halt!("Cannot check a metadata file without XML support: please install additional gems") unless MDQT::Client.verification_available? client = MDQT::Client.new( options.service, verbose: options.verbose, explain: options.explain ? true : false, ) halt!("Please specify a file to rename!") if args.empty? args.each do |filename| next if File.symlink?(filename) file = client.open_metadata(filename) halt!("Cannot access file #{filename}") unless file.readable? halt!("File #{filename} is a metadata aggregate, cannot rename to hashed entityID!") if file.aggregate? halt!("XML validation failed for #{filename}:\n#{file.validation_error}") unless file.valid? halt!("Cannot find entityID for #{filename}") unless file.entity_id newname = file.linkname # Using the same name as the link, not super-obvious next if filename == newname if file.turd? hey "Warning: will not process backup/turd files" next end message = "" if File.exist?(newname) if options.force File.delete(newname) else halt!("Cannot rename #{filename} to #{newname} - File exists! Use --force to override") next end end File.rename(filename, newname) if options.link File.delete(filename) if options.force && File.exist?(filename) File.symlink(newname, filename) unless newname == filename end hey("#{filename} renamed to #{newname} [#{file.entity_id}] #{message}") if options.verbose end end end private end end
Version data entries
11 entries across 11 versions & 2 rubygems