diff --git a/human-friendly-id-gen.cabal b/human-friendly-id-gen.cabal index 89b50da..54834df 100644 --- a/human-friendly-id-gen.cabal +++ b/human-friendly-id-gen.cabal @@ -2,7 +2,7 @@ -- -- see: https://github.com/sol/hpack -- --- hash: 0bb664d30c1e0572386dc9e95d45e1f5ec99b28b9c2e2722a81c52887647eb5b +-- hash: 0e683ac9d8dfb5f4d7ce10cbfd8e10b825fae281ba0c99bb21798b3482443854 name: human-friendly-id-gen version: 0.1.0.0 @@ -47,18 +47,19 @@ library , vector default-language: Haskell2010 -executable human-friendly-id-gen-exe +executable hfig main-is: Main.hs other-modules: Paths_human_friendly_id_gen hs-source-dirs: src-exe 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: base >=4.8 && <5 , human-friendly-id-gen , protolude + , text , turtle default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 0961c04..d35a4de 100644 --- a/package.yaml +++ b/package.yaml @@ -35,16 +35,18 @@ library: - text - vector executables: - human-friendly-id-gen-exe: + hfig: main: Main.hs source-dirs: src-exe ghc-options: - -threaded - -rtsopts - -with-rtsopts=-N + - -optP-Wno-nonportable-include-path dependencies: - human-friendly-id-gen - turtle + - text tests: human-friendly-id-gen-doctest: main: Main.hs diff --git a/src-exe/Main.hs b/src-exe/Main.hs index 9a2bd2c..67c32a2 100644 --- a/src-exe/Main.hs +++ b/src-exe/Main.hs @@ -3,6 +3,8 @@ module Main where import Protolude hiding (FilePath, die) import Turtle +import qualified Data.Text as Text + import qualified HFIG.Dictionary as Dict import qualified HFIG.Lovecraftian as Lovecraftian @@ -13,7 +15,7 @@ main = do opts <- options "Generate Human Friendly identifiers" optParser case genMode opts of 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 let file = case optDict opts of Just "english" -> "dictionaries/english.txt" @@ -39,9 +41,9 @@ optParser = AppOptions <*> optional (optInt "len" 'n' "complexity depends on the gen chosen") toGenMode :: Text -> Maybe GenMode -toGenMode "s" = Just Short -toGenMode "short" = Just Short -toGenMode "d" = Just Dict -toGenMode "dict" = Just Dict -toGenMode "dictionary" = Just Dict -toGenMode _ = Nothing +toGenMode "" = Nothing +toGenMode str + | str `Text.isPrefixOf` "short" = Just Short + | str `Text.isPrefixOf` "dictionary" = Just Dict + | str `Text.isPrefixOf` "lovecraftian" = Just Lovecraftian + | otherwise = Nothing