class Mp4Renamer::CLI

Public Instance Methods

execute() click to toggle source
# File lib/mp4_renamer/cli.rb, line 22
def execute
  opts = options.deep_symbolize_keys
  if opts[:version]
    puts "You are using Mp4Renamer version #{Mp4Renamer::VERSION}"
    exit
  end
  process(opts)
end
usage() click to toggle source
# File lib/mp4_renamer/cli.rb, line 32
    def usage
      puts <<-EOS
Usage:
  mp4_renamer [options]

Options:
  -b, [--base-dir=BASE_DIR]        # Starting directory
                                   # Default: . (current directory)
  -r, [--recursive=RECURSIVE]      # Perform the operation recursively
                                   # Default: true
  -c, [--commit], [--no-commit]    # Commit your changes
                                   # Default: --no-commit
  -v, [--version], [--no-version]  # Display version number
                                   # Default: --no-version

Execute the main program
      EOS
    end

Private Instance Methods

process(opts = {}) click to toggle source
# File lib/mp4_renamer/cli.rb, line 55
def process(opts = {})
  puts "FYI: your options #{opts.inspect}"
  # Note: currently `mp4info` gem supports only two extensions
  opts.merge!(exts: %w(mp4 m4a MP4 M4A))
  files = CodeLister.files(opts)

  if files.empty?
    puts "No files found for your options #{opts}"
    return
  end

  renamer = Renamer.new(opts[:commit])
  unless opts[:commit]
    puts '-----------------------------------------------------------------------'
    puts 'FYI: this is a dry-run only, to commit your changes use --commit option'
    puts '-----------------------------------------------------------------------'
  end
  files.each do |file|
    renamer.rename(file)
  end
end