From c740bbb7b7b20bd3bda2a17f2bf5fbd4e399b9a0 Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Sun, 28 Jul 2013 19:34:01 -0400
Subject: [PATCH] Prevent coordinates from being parsed as argument.

Fixes #493.
---
 lib/geocoder/cli.rb | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/geocoder/cli.rb b/lib/geocoder/cli.rb
index ab3df3b7..f4832a15 100644
--- a/lib/geocoder/cli.rb
+++ b/lib/geocoder/cli.rb
@@ -8,6 +8,11 @@ module Geocoder
       show_url  = false
       show_json = false
 
+      # remove arguments that are probably coordinates so they are not
+      # processed as arguments (eg: -31.96047031,115.84274631)
+      coords = args.select{ |i| i.match(/^-\d/) }
+      args -= coords
+
       OptionParser.new{ |opts|
         opts.banner = "Usage:\n    geocode [options] <location>"
         opts.separator "\nOptions: "
@@ -65,7 +70,9 @@ module Geocoder
         end
       }.parse!(args)
 
-      query = args.join(" ")
+      # concatenate args with coords that might have been removed
+      # before option processing
+      query = (args + coords).join(" ")
 
       if query == ""
         out << "Please specify a location (run `geocode -h` for more info).\n"
-- 
GitLab