~samhh/unerf

ref: 0.1.0 unerf/exec/CLI.hs -rw-r--r-- 1003 bytes
20359087 — Sam A. Horvath-Hunt 0.1.0 7 months ago
                                                                                
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
module CLI (parse, Opts (..)) where

import           Data.Version        (showVersion)
import qualified Options.Applicative as A
import           Paths_unerf         (version)
import           Prelude

newtype Opts = Opts
  { path :: Maybe Text
  }

parseFilePath :: A.Parser (Maybe Text)
parseFilePath = A.optional (A.argument A.str (A.metavar "path" <> A.help h))
  where h = "The path to check, defaulting to the current working directory"

parser :: A.Parser Opts
parser = Opts <$> parseFilePath

withHelp :: A.Parser a -> A.ParserInfo a
withHelp p = A.info (A.helper <*> v <*> p) (A.fullDesc <> A.progDesc d)
  where d = "Unearth build scripts in unfamiliar projects."
        v = A.infoOption (showVersion version) (A.short 'v' <> A.long "version" <> A.help "Output version")

-- | Parse command-line options. The library we're using for this will handle
-- the possibility of failure for us, which isn't encoded in the type
-- signature.
parse :: IO Opts
parse = A.execParser $ withHelp parser