nptools-0.2.2: nest.hs
import Data.Char (isDigit)
import System.Environment (getArgs)
import System.IO (hPutStr,stderr)
import System.Exit (exitFailure)
nest :: Int -> String -> String
nest i = unlines . map (s++) . lines
where s = replicate i ' '
main :: IO ()
main = do args <- getArgs
case args of
[arg] | all isDigit arg -> putStr . nest (read arg) =<< getContents
_ -> do hPutStr stderr . unlines $
["Usage: nest <number>"
,""
,"This program will write on standard output the contents"
,"read on standard input but nested by <number> spaces."
,""
,"Each gets indented by <number> spaces more."
]
exitFailure