This more of a style question, rather than a how to.
So I\'ve got a program that needs two command line arguments: a string and an integer.
I implemented it this
These days, I'm a big fan of optparse-generic for parsing command line arguments:
As your program matures, you may want to come up with a complete help, and a well-annotated options data type, which options-generic
is great at. But it's also great at parsing lists and tuples without any annotation at all, so you can hit the ground running:
For example
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Options.Generic
main :: IO ()
main = do
(n, c) <- getRecord "Example program"
putStrLn $ replicate n c
Runs as:
$ ./OptparseGenericExample
Missing: INT CHAR
Usage: OptparseGenericExample INT CHAR
$ ./OptparseGenericExample 5 c
ccccc