Sha256: 57d1b080ece9407b10b5e570a3d545ce2f884b03d84b474c798677229c657ebe

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

require 'optparse'

module EbookRenamer::Options

  def parse_options()
    options = {}

    option_parser = OptionParser.new do |opts|
      opts.banner = <<-END.gsub(/^\s+\|/, '')
        |
        | Usage: ebook_renamer [options]
        |
        | Examples:
        |
        |  1) $ebook_renamer
        |
        |  2) $ebook_renamer --base-dir ~/Dropbox/ebooks
        |
        |  3) $ebook_renamer --base-dir ~/Dropbox/ebooks
        |                    --recursive
        |
        |  4) $ebook_renamer --base-dir ~/Dropbox/ebooks
        |                    --recursive
        |
        |  5) $ebook_renamer --base-dir ~/Dropbox/ebooks
        |                    --recursive
        |                    --commit
        |
        |  6) $ebook_renamer --base-dir ~/Dropbox/ebooks
        |                    --meta-binary ebook-meta
        |                    --recursive
        |                    --commit
        |
        | Options:
        |
      END

      options[:base_dir] ||= Dir.pwd
      opts.on('-b', '--base-dir directory', 'Starting directory [default - current directory]') do |base_dir|
        options[:base_dir] = base_dir
      end

      options[:meta_binary] ||= 'ebook-meta'
      opts.on('-m', '--meta-binary path', "The ebook-meta executable [default - 'ebook-meta']") do |binary|
        options[:meta_binary] = binary
      end

      options[:recursive] = false
      opts.on('-r', '--recursive', 'Process the files recursively [default - false]') do
        options[:recursive] = true
      end

      options[:commit] = false
      opts.on('-c', '--commit', 'Perform the actual rename [default - false]') do
        options[:commit] = true
      end

      opts.on('-v', '--version', 'Display version number') do
        puts EbookRenamer::VERSION
        exit 0
      end

      opts.on('-h', '--help', 'Display this screen') do
        puts opts
        exit 0
      end
    end

    option_parser.parse!
    options
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ebook_renamer-0.0.6 lib/ebook_renamer/options.rb
ebook_renamer-0.0.5 lib/ebook_renamer/options.rb
ebook_renamer-0.0.4 lib/ebook_renamer/options.rb