-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
39 lines (30 loc) · 1.12 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{-# LANGUAGE OverloadedStrings #-}
module Main where
import GenPass
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Monoid
import System.Environment
import System.Exit
import System.IO
--
main :: IO ()
main = do
args <- map T.pack <$> getArgs
let subcommandMaybe =
if null args
then Just Gen
else readSubcommand (head args)
subcommand <- case subcommandMaybe of
Nothing -> T.hPutStrLn stderr "Need subcommand" >> exitFailure
Just x -> pure x
let rest = T.intercalate " " $ case args of { [] -> []; (_:t) -> t }
-- T.putStrLn [i|#{subcommand} #{rest}|]
-- parseTest parserSetting rest
let settingEither = parseSetting rest
Last settingMaybe <- case settingEither of
Left e -> T.hPutStrLn stderr (T.pack (show e)) >> exitFailure
Right setting_ -> pure $ validate $ defaultSetting <> setting_
case settingMaybe of
Nothing -> T.hPutStrLn stderr "insufficient arguments" >> exitFailure
Just setting -> runSetting subcommand setting