propellor/HostName.hs

19 lines
384 B
Haskell
Raw Normal View History

2014-03-30 04:08:02 +00:00
module HostName where
import Control.Applicative
import System.Environment
2014-03-30 05:17:19 +00:00
import Utility.Process
2014-03-30 04:08:02 +00:00
type HostName = String
getHostName :: IO HostName
getHostName = go =<< getArgs
where
go (h:_) = return h
2014-03-30 05:17:19 +00:00
go [] = do
s <- takeWhile (/= '\n') <$> readProcess "hostname" ["-f"]
if null s
then error "Cannot determine hostname! Pass it on the command line."
else return s