import App.Clk.Entry
import App.Clk.Util
import Data.List
import Data.Period
import Data.Time.Clock
import Data.Time.LocalTime
import System.Console.GetOpt
import System.Environment

data Flag = PeriodArg String -- -p or --period
options = [ Option ['p'] ["period"] (ReqArg PeriodArg "PERIOD") ""
          ]

main = do
    args <- getArgs
    let periodPhrase = case getOpt Permute options args of
                            ([PeriodArg p], [], []) -> p
                            otherwise               -> "today"
    period <- parsePeriod periodPhrase

    tz     <- getCurrentTimeZone
    entries <- fmap (filter $ isWithin period) mostRecentMonthEntries
    putStrLn $ intercalate "\n" $ map (showUser tz) $ entries

import App.Clk.Entry
import App.Clk.Util
import Data.List
import Data.Period
import Data.Time.Clock
import Data.Time.LocalTime
import System.Console.GetOpt
import System.Environment

data Flag = PeriodArg String -- -p or --period
options = [ Option ['p'] ["period"] (ReqArg PeriodArg "PERIOD") ""
          ]

main = do
    args <- getArgs
    let ( flags, _, _ ) = getOpt Permute options args
    period <- parsePeriod $ findPeriodPhrase flags

    tz     <- getCurrentTimeZone
    entries <- fmap (filter $ isWithin period) mostRecentMonthEntries
    putStrLn $ intercalate "\n" $ map (showUser tz) $ entries

findPeriodPhrase :: [Flag] -> String
findPeriodPhrase flags =
    case find isPeriodFlag flags of
        Just (PeriodArg p) -> p
        Nothing            -> "today"
    where isPeriodFlag (PeriodArg _) = True
          isPeriodFlag _              = False

Support multiple command line options
Support multiple command line options

The old approach assumed that any --period flag would be the first value
returned by getOpt.  Once the user can specify multiple flags, that
won't be true anymore.
