Skip to content
This repository has been archived by the owner on Dec 28, 2017. It is now read-only.

Commit

Permalink
Added OptionsParser for better command-line interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Cook committed Feb 27, 2013
1 parent 78eb2bc commit c9a407a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ $ epub_validator /path/to/sample.epub
Checking....FAILED!
This is not a valid EPUB 3.0 ebook.
ERROR: OPS/toc.ncx(21): 'OPS/': referenced resource exists, but not declared in the OPF file
```

Expand Down
41 changes: 31 additions & 10 deletions bin/epub_validator
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,46 @@

$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'optparse'
require 'epub_validator'

args = ARGV.dup
ARGV.clear
command = args.shift.strip rescue 'help'
args = ARGV

puts "\nChecking...."
validation = EpubValidator.check(command)
options = OptionParser.new do |opts|
opts.banner = "Usage: #{opts.program_name} [OPTIONS] /path/to/some.epub"
opts.separator ""
opts.separator "Common options:"

puts
puts "Detected as EPUB version #{validation.epub_version}" if validation.epub_version
puts
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("--version", "Show version") do
puts EpubValidator::VERSION
exit
end
end

args = ['-h'] if args.empty?
options.parse!(args)

filename = args.shift.strip
unless filename
puts "You must provide an EPUB filename"
exit
end

print "\nChecking...."
validation = EpubValidator.check(filename)

if validation.valid?
puts "...Passed.\n"
puts "Congratulations! This is a valid EPUB #{validation.epub_version} ebook."
puts
puts validation.messages
else
puts "FAILED!\n\n"
puts "FAILED!"
puts
puts "This is not a valid EPUB #{validation.epub_version} ebook."
puts
puts validation.messages
end
Expand Down
2 changes: 1 addition & 1 deletion lib/epub_validator/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module EpubValidator
VERSION = "1.0.1"
VERSION = "1.0.2"
end

0 comments on commit c9a407a

Please sign in to comment.