Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix bin/kpeg when there are no arguments passed in #27

Open
wants to merge 1 commit into from

1 participant

@sjothen

Was just playing around with a simple parser and noticed the following happens when you don't pass any arguments to kpeg:

sjothen@air% kpeg                                                    
/Library/Ruby/Gems/1.8/gems/kpeg-0.10.0/bin/kpeg:49:in `exists?': can't convert nil into String (TypeError)
    from /Library/Ruby/Gems/1.8/gems/kpeg-0.10.0/bin/kpeg:49
    from /usr/bin/kpeg:19:in `load'
    from /usr/bin/kpeg:19

This PR just adds a check after option parsing to print out the help information if no arguments are passed in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 22, 2013
  1. @sjothen
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 2 deletions.
  1. +9 −2 bin/kpeg
View
11 bin/kpeg
@@ -8,7 +8,7 @@ require 'kpeg/grammar_renderer'
require 'optparse'
options = {}
-OptionParser.new do |o|
+optparser = OptionParser.new do |o|
o.banner = "Usage: kpeg [options]"
o.on("-t", "--test", "Syntax check the file only") do |v|
@@ -42,7 +42,14 @@ OptionParser.new do |o|
o.on("-d", "--debug", "Debug parsing the file") do |v|
options[:debug] = v
end
-end.parse!
+end
+
+optparser.parse!
+
+if ARGV.empty?
+ puts optparser.help
+ exit 1
+end
file = ARGV.shift
Something went wrong with that request. Please try again.