This is a small example illustrating how to create a simple command line interface using command-line parsing combinators.
The command line syntax:
A file name is a non-empty argument that doesn't start with a dash.
Implementation of the functionality. Notice in particular how easy it is to implement the help command.
help = putStrLn (usage "silly" silly) date = print =<< getClockTime cat = mapM_ (putStr @@ readFile) ls True _ = fail "ls -l not implemented yet" ls False paths = mapM_ ls1 paths ls1 path = ifM (doesDirectoryExist path) (putStr . unlines =<< getDirectoryContents path) (ifM (doesFileExist path) (putStrLn path) (fail $ "No such file or directory: "++path))
(HTML for this module was generated on 2005-02-11. About the conversion tool.)