From 45f01962c4af012eb8c86916b239fe596a85f994 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 20 Apr 2009 13:00:10 +0200 Subject: [PATCH] Implement error checks for extra arguments 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 | 7 ++++++- hn1.hs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hbal.hs b/hbal.hs index a606077..7424b3d 100644 --- 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 --- 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" -- 1.7.10.4