module Conferer.Source.CLIArgs
(
mkCLIArgsSource
, mkCLIArgsSource'
, parseArgsIntoKeyValue
)
where
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Maybe (mapMaybe)
import Data.String (fromString)
import System.Environment (getArgs)
import Conferer.Types
import Conferer.Source.Simple
mkCLIArgsSource' :: [String] -> SourceCreator
mkCLIArgsSource' args = \config -> do
let configMap = parseArgsIntoKeyValue args
mkMapSource configMap config
mkCLIArgsSource :: SourceCreator
mkCLIArgsSource = \config -> do
args <- getArgs
mkCLIArgsSource' args config
parseArgsIntoKeyValue :: [String] -> [(Key, Text)]
parseArgsIntoKeyValue =
fmap (\(k, s) -> (fromString $ Text.unpack k, s)) .
fmap (\s -> fmap (Text.drop 1) $ Text.breakOn "=" s).
mapMaybe (Text.stripPrefix "--") .
takeWhile (/= "--") .
fmap Text.pack