Commit 3005fa53 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

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
parent 0e749250
......@@ -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
{-# 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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment