Skip to content

Commit

Permalink
Share optpars-applicative utils across executables
Browse files Browse the repository at this point in the history
  • Loading branch information
samtay committed Dec 15, 2016
1 parent d7f7c03 commit 9ccd7ab
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
13 changes: 1 addition & 12 deletions app/Dm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Main where

-- Local packages
import Dockmaster
import Options.Utils

-- External packages
import Shelly
Expand Down Expand Up @@ -79,15 +80,3 @@ opts defaultCompDir = info (helper <*> parser defaultCompDir)
<> progDesc "Orchestrate your docker-compose"
<> header "dm - yaml loving docker compose orchestration"
)

-- | 'Text' option
textOption :: Mod OptionFields String -> Parser T.Text
textOption = fmap T.pack . strOption

-- | 'Text' argument type
text :: ReadM T.Text
text = str >>= return . T.pack

-- | 'FilePath' option
filePathOption :: Mod OptionFields String -> Parser FilePath
filePathOption = fmap fromText . textOption
1 change: 1 addition & 0 deletions app/Dmc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Main where

-- Local packages
import Dockmaster
import Options.Utils

-- External packages
import Shelly hiding (command)
Expand Down
5 changes: 4 additions & 1 deletion dockmaster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ description:
library
hs-source-dirs: src
exposed-modules: Dockmaster
, Options.Utils
other-modules: Dockmaster.Compose
, Dockmaster.Config.Parser
, Dockmaster.Config.Types
Expand All @@ -36,6 +37,7 @@ library
, text
, unordered-containers
, yaml
, optparse-applicative
default-language: Haskell2010

executable dm
Expand All @@ -55,9 +57,10 @@ executable dmc
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, dockmaster
, either >= 4.4.1.1
, optparse-applicative
, shelly
, text
, optparse-applicative
default-language: Haskell2010

test-suite dockmaster-test
Expand Down
32 changes: 32 additions & 0 deletions src/Options/Utils.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{-|
Module : Options.Utils
Description : Options.Applicative utilities
License : ASL-2
Maintainer : [email protected]
Stability : experimental
Portability : POSIX
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
module Options.Utils where

import Options.Applicative
import Shelly (FilePath, fromText)
import Prelude hiding (FilePath)
import Data.Monoid ((<>))
import qualified Data.Text as T

default (T.Text)

-- | 'Text' option
textOption :: Mod OptionFields String -> Parser T.Text
textOption = fmap T.pack . strOption

-- | 'Text' argument type
text :: ReadM T.Text
text = str >>= return . T.pack

-- | 'FilePath' option
filePathOption :: Mod OptionFields String -> Parser FilePath
filePathOption = fmap fromText . textOption

0 comments on commit 9ccd7ab

Please sign in to comment.