Improve error messages from pwd
authorIan Lynagh <igloo@earth.li>
Fri, 4 Jul 2008 23:33:43 +0000 (23:33 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 4 Jul 2008 23:33:43 +0000 (23:33 +0000)
utils/pwd/pwd.hs

index 264cc98..45a2d46 100644 (file)
@@ -3,15 +3,21 @@ module Main where
 
 import System.Directory
 import System.Environment
+import System.Exit
+import System.IO
 
 main :: IO ()
-main = do args <- getArgs
-          let escape = case args of
-                       ["quadruple-backslash"] -> escape_quadruple_backslash
-                       ["forwardslash"] -> escape_forwardslash
-                       _ -> error ("pwd: Bad args: " ++ show args)
-          d <- getCurrentDirectory
-          putStr $ concatMap escape d
+main = do
+    args <- getArgs
+    escape <- case args of
+              ["quadruple-backslash"] -> return escape_quadruple_backslash
+              ["forwardslash"] ->        return escape_forwardslash
+              _ -> do hPutStrLn stderr ("Bad args: " ++ show args)
+                      hPutStrLn stderr
+                                "Usage: pwd {forwardslash|quadruple-backslash}"
+                      exitFailure
+    d <- getCurrentDirectory
+    putStr $ concatMap escape d
 
 -- In prog006 we have to escape \ twice, once to get through sed and
 -- again to get through parsing pkg.conf