diff options
Diffstat (limited to 'src/main.hs')
-rw-r--r-- | src/main.hs | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/main.hs b/src/main.hs index 7b08e64..b0baaa4 100644 --- a/src/main.hs +++ b/src/main.hs @@ -67,7 +67,10 @@ stateOpt str = -optionHeader = "Usage: stv [OPTION...]" +optionHeader = + "Usage: stv [OPTION...]\n\n" ++ + "Note that the -c, -p, -o, -e, -s options are all\n" ++ + "required for normal operation.\n" optionData :: [Opt.OptDescr (Options -> Options)] optionData = @@ -85,18 +88,18 @@ optionData = , Opt.Option ['c'] ["candidates"] (Opt.ReqArg (\c opts -> opts { getCandFile = Just c }) "FILE") - "file containing AEC candidate data" + ".csv file containing AEC candidate data" , Opt.Option ['p'] ["preferences"] (Opt.ReqArg (\p opts -> opts { getPrefFile = Just p}) "FILE") - "file containing AEC formal preferences" + ".csv file containing AEC formal preferences" , Opt.Option ['o'] ["outdir"] (Opt.ReqArg (\d opts -> opts { getOutDir = Just d}) "DIR") - "directory to output count logging" + "new directory to output count logging" , Opt.Option ['e'] ["elect"] - (Opt.ReqArg electOpt "NUM") + (Opt.ReqArg electOpt "INT") "number of candidates to elect" , Opt.Option ['s'] ["state"] @@ -115,6 +118,14 @@ getOpts argv = +furtherHelp :: String +furtherHelp = + "Please be sure to provide all required options to run the election counter.\n" ++ + "For further information consult '--help'.\n" + + + + main = do rawArgs <- Env.getArgs (options, arguments) <- getOpts rawArgs @@ -134,42 +145,47 @@ main = do -- both present and valid let candidateFile = Maybe.fromJust (getCandFile options) Con.when (Maybe.isNothing (getCandFile options)) $ - Ex.die "Candidate data file not provided" + Ex.die ("Candidate data file not provided.\n\n" ++ furtherHelp) doesExist <- Dir.doesFileExist candidateFile Con.when (not doesExist) $ - Ex.die "Candidate data file does not exist" + Ex.die ("Candidate data file does not exist.\n\n" ++ furtherHelp) let preferenceFile = Maybe.fromJust (getPrefFile options) Con.when (Maybe.isNothing (getPrefFile options)) $ - Ex.die "Formal preference data file not provided" + Ex.die ("Formal preference data file not provided.\n\n" ++ furtherHelp) doesExist <- Dir.doesFileExist preferenceFile Con.when (not doesExist) $ - Ex.die "Formal preference data file does not exist" + Ex.die ("Formal preference data file does not exist.\n\n" ++ furtherHelp) let outputDir = Maybe.fromJust (getOutDir options) Con.when (Maybe.isNothing (getOutDir options)) $ - Ex.die "Output logging directory not provided" + Ex.die ("Output logging directory not provided.\n\n" ++ furtherHelp) doesExist <- Dir.doesDirectoryExist outputDir Con.when doesExist $ - Ex.die "Output directory already exists" + Ex.die ("Output directory already exists.\n\n" ++ furtherHelp) let numToElect = Maybe.fromJust (getNumToElect options) Con.when (Maybe.isNothing (getNumToElect options)) $ - Ex.die "Invalid number of candidates to elect or number not provided" + Ex.die ("Invalid number of candidates to elect or number not provided.\n\n" ++ furtherHelp) let state = Maybe.fromJust (getState options) Con.when (Maybe.isNothing (getState options)) $ - Ex.die "Invalid state/territory or state/territory not provided" + Ex.die ("Invalid state/territory or state/territory not provided.\n\n" ++ furtherHelp) -- set up the election processing (aboveBallot, belowBallot) <- Cand.readCandidates candidateFile state + Con.when (isVerbose options) $ putStrLn "Reading preference data..." counter <- Sen.createSenateCounter preferenceFile aboveBallot belowBallot + Con.when (isVerbose options) $ putStrLn "Done.\n" Dir.createDirectory outputDir - election <- Elt.createElection outputDir counter numToElect + Con.when (isVerbose options) $ putStrLn "Setting up election..." + election <- Elt.createElection outputDir counter numToElect (isVerbose options) + Con.when (isVerbose options) $ putStrLn "Done.\n" -- run the show + Con.when (isVerbose options) $ putStrLn "Running...\n" Elt.doCount election |