Implement error checks for extra arguments
authorIustin Pop <iustin@google.com>
Mon, 20 Apr 2009 11:00:10 +0000 (13:00 +0200)
committerIustin Pop <iustin@google.com>
Mon, 20 Apr 2009 11:00:10 +0000 (13:00 +0200)
Neither hbal nor hn1 take any arguments beside the options, so if any
are passed is most likely an unintended error. This patch aborts in such
cases.

hbal.hs
hn1.hs

diff --git a/hbal.hs b/hbal.hs
index a606077..7424b3d 100644 (file)
--- a/hbal.hs
+++ b/hbal.hs
@@ -141,7 +141,12 @@ iterateDepth ini_tbl max_rounds ktn kti nmlen imlen cmd_strs oneline =
 main :: IO ()
 main = do
   cmd_args <- System.getArgs
-  (opts, _) <- CLI.parseOpts cmd_args "hbal" options defaultOptions optShowHelp
+  (opts, args) <- CLI.parseOpts cmd_args "hbal" options
+                  defaultOptions optShowHelp
+
+  unless (null args) $ do
+         hPutStrLn stderr "Error: this program doesn't take any arguments."
+         exitWith $ ExitFailure 1
 
   when (optShowVer opts) $ do
          putStr $ CLI.showVersion "hbal"
diff --git a/hn1.hs b/hn1.hs
index 4140674..65ab4bb 100644 (file)
--- a/hn1.hs
+++ b/hn1.hs
@@ -123,7 +123,12 @@ options =
 main :: IO ()
 main = do
   cmd_args <- System.getArgs
-  (opts, _) <- CLI.parseOpts cmd_args "hn1" options defaultOptions optShowHelp
+  (opts, args) <- CLI.parseOpts cmd_args "hn1" options
+                  defaultOptions optShowHelp
+
+  unless (null args) $ do
+         hPutStrLn stderr "Error: this program doesn't take any arguments."
+         exitWith $ ExitFailure 1
 
   when (optShowVer opts) $ do
          printf $ CLI.showVersion "hn1"