replace m >>= return . f with fmap f m
This commit is contained in:
parent
5880d11869
commit
7d95a3730c
13
main.hs
13
main.hs
@ -17,14 +17,15 @@ data ProgArgs = ProgArgs
|
|||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
parser :: IO (ParserSpec ProgArgs)
|
parser :: IO (ParserSpec ProgArgs)
|
||||||
parser = path >>= \path -> return $ ProgArgs
|
parser = (\path -> ProgArgs
|
||||||
`parsedBy` boolFlag "interactive" `Descr` "Manually insert numbers"
|
`parsedBy` boolFlag "interactive" `Descr` "Manually insert numbers"
|
||||||
`andBy` optFlag path "dictionary" `Descr` "Specify dictionary file path"
|
`andBy` optFlag path "dictionary" `Descr` "Specify dictionary file path"
|
||||||
`andBy` optFlag 6 "lenght" `Descr` "Number of words in a passphrase"
|
`andBy` optFlag 6 "lenght" `Descr` "Number of words in a passphrase"
|
||||||
`andBy` optFlag 1 "phrases" `Descr` "Number of passphrases to generate"
|
`andBy` optFlag 1 "phrases" `Descr` "Number of passphrases to generate")
|
||||||
|
<$> path
|
||||||
|
|
||||||
interface :: IO (CmdLnInterface ProgArgs)
|
interface :: IO (CmdLnInterface ProgArgs)
|
||||||
interface =
|
interface =
|
||||||
(`setAppDescr` "A diceware passphrase generator") <$>
|
(`setAppDescr` "A diceware passphrase generator") <$>
|
||||||
(`setAppEpilog` "Alea iacta est.") <$>
|
(`setAppEpilog` "Alea iacta est.") <$>
|
||||||
(mkApp =<< parser)
|
(mkApp =<< parser)
|
||||||
@ -39,7 +40,7 @@ path = getDataFileName "dict/diceware"
|
|||||||
-- Read dictionary file
|
-- Read dictionary file
|
||||||
readDict :: ProgArgs -> IO ProgArgs
|
readDict :: ProgArgs -> IO ProgArgs
|
||||||
readDict args@ProgArgs{..} =
|
readDict args@ProgArgs{..} =
|
||||||
readFile dictionary >>= \x -> return args {dictionary = x}
|
(\x -> args {dictionary = x}) <$> readFile dictionary
|
||||||
|
|
||||||
-- Main function
|
-- Main function
|
||||||
exec :: ProgArgs -> IO ()
|
exec :: ProgArgs -> IO ()
|
||||||
@ -47,8 +48,8 @@ exec args@ProgArgs{..} =
|
|||||||
if interactive
|
if interactive
|
||||||
then interact (unlines . map dice . lines)
|
then interact (unlines . map dice . lines)
|
||||||
else do
|
else do
|
||||||
randWords dictSize phraseLength >>= putStrLn . unwords . map dice'
|
randWords dictSize phraseLength >>= putStrLn . unwords . map dice'
|
||||||
when (phrases > 1) $ exec args {phrases = phrases - 1}
|
when (phrases > 1) $ exec args {phrases = phrases - 1}
|
||||||
where
|
where
|
||||||
(dict, dictSize) = (parseDiceware dictionary, length dict)
|
(dict, dictSize) = (parseDiceware dictionary, length dict)
|
||||||
dice n = readDiceware dict (read n :: Int)
|
dice n = readDiceware dict (read n :: Int)
|
||||||
|
Loading…
Reference in New Issue
Block a user