Add a argument parser and some haddocks
I am not sure if I have set the ParserInfo up correctly, I have never used it before.
This commit is contained in:
parent
c9e5a20a3e
commit
85df08a913
@ -17,10 +17,12 @@
|
||||
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
|
||||
|
||||
module Language.Haskell.GhcMod.Options.Options (
|
||||
globalArgSpec
|
||||
globalArgSpec
|
||||
, parseCmdLineOptions
|
||||
) where
|
||||
|
||||
import Options.Applicative
|
||||
import Options.Applicative.Help.Chunk
|
||||
import Options.Applicative.Types
|
||||
import Language.Haskell.GhcMod.Types
|
||||
import Control.Arrow
|
||||
@ -30,6 +32,22 @@ import Language.Haskell.GhcMod.Read
|
||||
import Language.Haskell.GhcMod.Options.DocUtils
|
||||
import Language.Haskell.GhcMod.Options.Help
|
||||
|
||||
-- | Parse a set of arguments according to the ghc-mod CLI flag spec, producing
|
||||
-- @Options@ set accordingly.
|
||||
parseCmdLineOptions :: [String] -> Maybe Options
|
||||
parseCmdLineOptions args = execParserMaybe parserInfo args
|
||||
where
|
||||
parserInfo
|
||||
= ParserInfo
|
||||
{ infoParser = globalArgSpec
|
||||
, infoFullDesc = True
|
||||
, infoProgDesc = Chunk Nothing
|
||||
, infoHeader = Chunk Nothing
|
||||
, infoFooter = Chunk Nothing
|
||||
, infoFailureCode = -1
|
||||
, infoIntersperse = True
|
||||
}
|
||||
|
||||
splitOn :: Eq a => a -> [a] -> ([a], [a])
|
||||
splitOn c = second (drop 1) . break (==c)
|
||||
|
||||
@ -119,6 +137,9 @@ programsArgSpec = Programs
|
||||
<=> showDefault
|
||||
<=> help "stack executable to use"
|
||||
|
||||
-- | An optparse-applicative @Parser@ sepcification for @Options@ so that
|
||||
-- applications making use of the ghc-mod API can have a consistent way of
|
||||
-- parsing global options.
|
||||
globalArgSpec :: Parser Options
|
||||
globalArgSpec = Options
|
||||
<$> outputOptsSpec
|
||||
|
Loading…
Reference in New Issue
Block a user