#!/usr/bin/env ruby require 'thor' lib = File.expand_path(File.dirname(__FILE__) + '/../lib') $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) require 'propre' require 'propre/version' class CLI < Thor include Propre desc 'lint [FILENAME...]', 'Sanitize the specified file. Use --dry for dry run' option :dry, type: :boolean option :color, type: :boolean, default: true def lint(*args) String.disable_colorization(true) unless options[:color] args.each do |oldpath| basename, newname, metadata = Propre.basename_newname_metadata(oldpath) working_directory = File.dirname(oldpath) newpath = "#{File.join(working_directory, newname + File.extname(oldpath))}" if options[:dry] unchanged = basename == newname ? :green : :yellow puts "#{oldpath} -> #{newpath}".colorize(unchanged) else File.rename(oldpath, "#{newpath}") end end end default_task :lint desc 'metadata [FILENAME]', 'Show metadata about the specified movie or episode' option :format, default: 'json' def metadata(filename) basename, newname, metadata = Propre.basename_newname_metadata(filename) metadata[:title] = newname puts metadata.to_json end map %w(--version -v) => :__version desc '--version, -v', 'Show version information about this program and quit.' def __version puts "#{Propre} - v#{Version::VERSION}" end end CLI.start(ARGV)