Skip to content

Commit

Permalink
Store data files in cabal data directory
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Jan 26, 2012
1 parent 1e49396 commit ae6667a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Options.hs
Expand Up @@ -4,16 +4,20 @@ import Data.List (foldl')
import System.Console.GetOpt
import System.Environment

import Paths_vty_hangman_helper

data Options = Options
{ scrubOption :: Bool
, wordlistFile :: FilePath
}

defaultOptions :: Options
defaultOptions = Options
{ scrubOption = False
, wordlistFile = "wordlist1.txt"
}
defaultOptions :: IO Options
defaultOptions = do
file <- getDataFileName "wordlist1.txt"
return Options
{ scrubOption = False
, wordlistFile = file
}

setScrub :: Bool -> Options -> Options
setScrub x o = o { scrubOption = x }
Expand All @@ -30,8 +34,9 @@ options =
parseOptions :: IO (Options, String)
parseOptions = do
args <- getArgs
opts <- defaultOptions
case getOpt Permute options args of
(optFuns, [w], [] ) -> return (foldl' (\x f -> f x) defaultOptions optFuns, w)
(optFuns, [w], [] ) -> return (foldl' (\x f -> f x) opts optFuns, w)
(_, [] , [] ) -> fail "Initial word not specified"
(_, _ , [] ) -> fail "Too many arguments"
(_, _ , errs) -> fail (unlines errs)
Expand Down

0 comments on commit ae6667a

Please sign in to comment.