better generator dispatcher and defaults

This commit is contained in:
Yann Esposito (Yogsototh) 2018-09-04 14:35:30 +02:00
parent a2f08d9d4b
commit 28e188ae39
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
3 changed files with 16 additions and 11 deletions

View file

@ -2,7 +2,7 @@
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: 0bb664d30c1e0572386dc9e95d45e1f5ec99b28b9c2e2722a81c52887647eb5b -- hash: 0e683ac9d8dfb5f4d7ce10cbfd8e10b825fae281ba0c99bb21798b3482443854
name: human-friendly-id-gen name: human-friendly-id-gen
version: 0.1.0.0 version: 0.1.0.0
@ -47,18 +47,19 @@ library
, vector , vector
default-language: Haskell2010 default-language: Haskell2010
executable human-friendly-id-gen-exe executable hfig
main-is: Main.hs main-is: Main.hs
other-modules: other-modules:
Paths_human_friendly_id_gen Paths_human_friendly_id_gen
hs-source-dirs: hs-source-dirs:
src-exe src-exe
default-extensions: OverloadedStrings NoImplicitPrelude ScopedTypeVariables default-extensions: OverloadedStrings NoImplicitPrelude ScopedTypeVariables
ghc-options: -Wall -Wcompat -Wincomplete-uni-patterns -Wredundant-constraints -Wnoncanonical-monad-instances -Werror -O2 -threaded -rtsopts -with-rtsopts=-N ghc-options: -Wall -Wcompat -Wincomplete-uni-patterns -Wredundant-constraints -Wnoncanonical-monad-instances -Werror -O2 -threaded -rtsopts -with-rtsopts=-N -optP-Wno-nonportable-include-path
build-depends: build-depends:
base >=4.8 && <5 base >=4.8 && <5
, human-friendly-id-gen , human-friendly-id-gen
, protolude , protolude
, text
, turtle , turtle
default-language: Haskell2010 default-language: Haskell2010

View file

@ -35,16 +35,18 @@ library:
- text - text
- vector - vector
executables: executables:
human-friendly-id-gen-exe: hfig:
main: Main.hs main: Main.hs
source-dirs: src-exe source-dirs: src-exe
ghc-options: ghc-options:
- -threaded - -threaded
- -rtsopts - -rtsopts
- -with-rtsopts=-N - -with-rtsopts=-N
- -optP-Wno-nonportable-include-path
dependencies: dependencies:
- human-friendly-id-gen - human-friendly-id-gen
- turtle - turtle
- text
tests: tests:
human-friendly-id-gen-doctest: human-friendly-id-gen-doctest:
main: Main.hs main: Main.hs

View file

@ -3,6 +3,8 @@ module Main where
import Protolude hiding (FilePath, die) import Protolude hiding (FilePath, die)
import Turtle import Turtle
import qualified Data.Text as Text
import qualified HFIG.Dictionary as Dict import qualified HFIG.Dictionary as Dict
import qualified HFIG.Lovecraftian as Lovecraftian import qualified HFIG.Lovecraftian as Lovecraftian
@ -13,7 +15,7 @@ main = do
opts <- options "Generate Human Friendly identifiers" optParser opts <- options "Generate Human Friendly identifiers" optParser
case genMode opts of case genMode opts of
Short -> Short.idgen (fromMaybe 4 (optLen opts)) >>= putText Short -> Short.idgen (fromMaybe 4 (optLen opts)) >>= putText
Lovecraftian -> Lovecraftian.idgen (fromMaybe 2 (optLen opts)) >>= putText Lovecraftian -> Lovecraftian.idgen (fromMaybe 1 (optLen opts)) >>= putText
Dict -> do Dict -> do
let file = case optDict opts of let file = case optDict opts of
Just "english" -> "dictionaries/english.txt" Just "english" -> "dictionaries/english.txt"
@ -39,9 +41,9 @@ optParser = AppOptions
<*> optional (optInt "len" 'n' "complexity depends on the gen chosen") <*> optional (optInt "len" 'n' "complexity depends on the gen chosen")
toGenMode :: Text -> Maybe GenMode toGenMode :: Text -> Maybe GenMode
toGenMode "s" = Just Short toGenMode "" = Nothing
toGenMode "short" = Just Short toGenMode str
toGenMode "d" = Just Dict | str `Text.isPrefixOf` "short" = Just Short
toGenMode "dict" = Just Dict | str `Text.isPrefixOf` "dictionary" = Just Dict
toGenMode "dictionary" = Just Dict | str `Text.isPrefixOf` "lovecraftian" = Just Lovecraftian
toGenMode _ = Nothing | otherwise = Nothing