summaryrefslogtreecommitdiff
path: root/iserv
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2016-08-30 17:06:08 -0400
committerBen Gamari <ben@smart-cactus.org>2016-08-31 13:15:33 -0400
commit3005fa5313b6d5fd9d4f47192c84e96e94ee7f17 (patch)
tree13f42f4b2436c191f9df0cfa8088f4e1d8b91993 /iserv
parent0e7492508cefbcabb4cf1398cfb3669edb72db77 (diff)
downloadhaskell-3005fa5313b6d5fd9d4f47192c84e96e94ee7f17.tar.gz
iserv: Show usage message on argument parse failure
Test Plan: validate Reviewers: simonmar, erikd, austin Reviewed By: simonmar, erikd Subscribers: thomie, erikd Differential Revision: https://phabricator.haskell.org/D2494 GHC Trac Issues: #12491
Diffstat (limited to 'iserv')
-rw-r--r--iserv/iserv-bin.cabal4
-rw-r--r--iserv/src/Main.hs26
2 files changed, 25 insertions, 5 deletions
diff --git a/iserv/iserv-bin.cabal b/iserv/iserv-bin.cabal
index 3fd5d2bd28..eb332771bf 100644
--- a/iserv/iserv-bin.cabal
+++ b/iserv/iserv-bin.cabal
@@ -26,5 +26,7 @@ Executable iserv
deepseq >= 1.4 && < 1.5,
ghci == 8.1
- if !os(windows)
+ if os(windows)
+ Cpp-Options: -DWINDOWS
+ else
Build-Depends: unix >= 2.7 && < 2.8
diff --git a/iserv/src/Main.hs b/iserv/src/Main.hs
index 66e15c9785..8c76e1fe71 100644
--- a/iserv/src/Main.hs
+++ b/iserv/src/Main.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE RecordWildCards, GADTs, ScopedTypeVariables, RankNTypes #-}
+{-# LANGUAGE CPP, RecordWildCards, GADTs, ScopedTypeVariables, RankNTypes #-}
-- |
-- The Remote GHCi server.
@@ -23,14 +23,32 @@ import System.Environment
import System.Exit
import Text.Printf
+dieWithUsage :: IO a
+dieWithUsage = do
+ prog <- getProgName
+ die $ prog ++ ": " ++ msg
+ where
+#ifdef WINDOWS
+ msg = "usage: iserv <write-handle> <read-handle> [-v]"
+#else
+ msg = "usage: iserv <write-fd> <read-fd> [-v]"
+#endif
+
main :: IO ()
main = do
- (arg0:arg1:rest) <- getArgs
- let wfd1 = read arg0; rfd2 = read arg1
+ args <- getArgs
+ (wfd1, rfd2, rest) <-
+ case args of
+ arg0:arg1:rest -> do
+ let wfd1 = read arg0
+ rfd2 = read arg1
+ return (wfd1, rfd2, rest)
+ _ -> dieWithUsage
+
verbose <- case rest of
["-v"] -> return True
[] -> return False
- _ -> die "iserv: syntax: iserv <write-fd> <read-fd> [-v]"
+ _ -> dieWithUsage
when verbose $ do
printf "GHC iserv starting (in: %d; out: %d)\n"
(fromIntegral rfd2 :: Int) (fromIntegral wfd1 :: Int)