From 1cc97db24f8cbeb24891d90669cb8313ace4360d Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Mon, 8 Feb 2016 22:34:20 +0200 Subject: [PATCH 1/8] Move the CLI parser definitions into the lib So they can be used by library clients to parse and pass in the appropriate ghc-mod Options. --- .../Haskell/GhcMod}/Options/Commands.hs | 6 +++--- .../Haskell/GhcMod}/Options/DocUtils.hs | 2 +- .../Haskell/GhcMod}/Options/Help.hs | 2 +- .../Haskell/GhcMod/Options}/Options.hs | 12 ++++++------ .../Haskell/GhcMod}/Options/ShellParse.hs | 2 +- .../Haskell/GhcMod/Options}/Version.hs | 2 +- ghc-mod.cabal | 15 ++++++++------- src/GHCMod.hs | 2 +- 8 files changed, 22 insertions(+), 21 deletions(-) rename {src/GHCMod => Language/Haskell/GhcMod}/Options/Commands.hs (98%) rename {src/GHCMod => Language/Haskell/GhcMod}/Options/DocUtils.hs (96%) rename {src/GHCMod => Language/Haskell/GhcMod}/Options/Help.hs (97%) rename {src/GHCMod => Language/Haskell/GhcMod/Options}/Options.hs (95%) rename {src/GHCMod => Language/Haskell/GhcMod}/Options/ShellParse.hs (95%) rename {src/GHCMod => Language/Haskell/GhcMod/Options}/Version.hs (95%) diff --git a/src/GHCMod/Options/Commands.hs b/Language/Haskell/GhcMod/Options/Commands.hs similarity index 98% rename from src/GHCMod/Options/Commands.hs rename to Language/Haskell/GhcMod/Options/Commands.hs index 2e1f60a..b39663a 100644 --- a/src/GHCMod/Options/Commands.hs +++ b/Language/Haskell/GhcMod/Options/Commands.hs @@ -16,15 +16,15 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-unused-do-bind #-} -module GHCMod.Options.Commands where +module Language.Haskell.GhcMod.Options.Commands where import Options.Applicative import Options.Applicative.Types import Options.Applicative.Builder.Internal import Language.Haskell.GhcMod.Types import Language.Haskell.GhcMod.Read -import GHCMod.Options.DocUtils -import GHCMod.Options.Help +import Language.Haskell.GhcMod.Options.DocUtils +import Language.Haskell.GhcMod.Options.Help type Symbol = String type Expr = String diff --git a/src/GHCMod/Options/DocUtils.hs b/Language/Haskell/GhcMod/Options/DocUtils.hs similarity index 96% rename from src/GHCMod/Options/DocUtils.hs rename to Language/Haskell/GhcMod/Options/DocUtils.hs index 95fad26..c81dec8 100644 --- a/src/GHCMod/Options/DocUtils.hs +++ b/Language/Haskell/GhcMod/Options/DocUtils.hs @@ -14,7 +14,7 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -module GHCMod.Options.DocUtils ( +module Language.Haskell.GhcMod.Options.DocUtils ( ($$), ($$$), (<=>), diff --git a/src/GHCMod/Options/Help.hs b/Language/Haskell/GhcMod/Options/Help.hs similarity index 97% rename from src/GHCMod/Options/Help.hs rename to Language/Haskell/GhcMod/Options/Help.hs index 9e33194..d43b6fb 100644 --- a/src/GHCMod/Options/Help.hs +++ b/Language/Haskell/GhcMod/Options/Help.hs @@ -15,7 +15,7 @@ -- along with this program. If not, see . {-# LANGUAGE OverloadedStrings, FlexibleInstances, GeneralizedNewtypeDeriving #-} -module GHCMod.Options.Help where +module Language.Haskell.GhcMod.Options.Help where import Options.Applicative import Options.Applicative.Help.Pretty (Doc) diff --git a/src/GHCMod/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs similarity index 95% rename from src/GHCMod/Options.hs rename to Language/Haskell/GhcMod/Options/Options.hs index 0a2a73e..6f95e02 100644 --- a/src/GHCMod/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -16,7 +16,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-unused-do-bind #-} -module GHCMod.Options ( +module Language.Haskell.GhcMod.Options.Options ( parseArgs, parseArgsInteractive, GhcModCommands(..) @@ -29,11 +29,11 @@ import Control.Arrow import Data.Char (toUpper, toLower) import Data.List (intercalate) import Language.Haskell.GhcMod.Read -import GHCMod.Options.Commands -import GHCMod.Version -import GHCMod.Options.DocUtils -import GHCMod.Options.Help -import GHCMod.Options.ShellParse +import Language.Haskell.GhcMod.Options.Commands +import Language.Haskell.GhcMod.Options.Version +import Language.Haskell.GhcMod.Options.DocUtils +import Language.Haskell.GhcMod.Options.Help +import Language.Haskell.GhcMod.Options.ShellParse parseArgs :: IO (Options, GhcModCommands) parseArgs = diff --git a/src/GHCMod/Options/ShellParse.hs b/Language/Haskell/GhcMod/Options/ShellParse.hs similarity index 95% rename from src/GHCMod/Options/ShellParse.hs rename to Language/Haskell/GhcMod/Options/ShellParse.hs index acd609b..a807932 100644 --- a/src/GHCMod/Options/ShellParse.hs +++ b/Language/Haskell/GhcMod/Options/ShellParse.hs @@ -13,7 +13,7 @@ -- -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -module GHCMod.Options.ShellParse (parseCmdLine) where +module Language.Haskell.GhcMod.Options.ShellParse (parseCmdLine) where import Data.Char import Data.List diff --git a/src/GHCMod/Version.hs b/Language/Haskell/GhcMod/Options/Version.hs similarity index 95% rename from src/GHCMod/Version.hs rename to Language/Haskell/GhcMod/Options/Version.hs index 2bf6db2..72d7371 100644 --- a/src/GHCMod/Version.hs +++ b/Language/Haskell/GhcMod/Options/Version.hs @@ -14,7 +14,7 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -module GHCMod.Version where +module Language.Haskell.GhcMod.Options.Version where import Paths_ghc_mod import Data.Version (showVersion) diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 01358b5..def5ce7 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -152,6 +152,13 @@ Library Language.Haskell.GhcMod.Types Language.Haskell.GhcMod.Utils Language.Haskell.GhcMod.World + + Language.Haskell.GhcMod.Options.Options + Language.Haskell.GhcMod.Options.Commands + Language.Haskell.GhcMod.Options.Version + Language.Haskell.GhcMod.Options.DocUtils + Language.Haskell.GhcMod.Options.ShellParse + Language.Haskell.GhcMod.Options.Help Other-Modules: Paths_ghc_mod Utils Data.Binary.Generic @@ -187,6 +194,7 @@ Library , extra == 1.4.* , pipes == 4.1.* , safe < 0.4 && >= 0.3.9 + , optparse-applicative >=0.11.0 && <0.13.0 if impl(ghc < 7.8) Build-Depends: convertible if impl(ghc < 7.5) @@ -198,12 +206,6 @@ Executable ghc-mod Default-Language: Haskell2010 Main-Is: GHCMod.hs Other-Modules: Paths_ghc_mod - , GHCMod.Options - , GHCMod.Options.Commands - , GHCMod.Version - , GHCMod.Options.DocUtils - , GHCMod.Options.ShellParse - , GHCMod.Options.Help GHC-Options: -Wall -fno-warn-deprecations -threaded Default-Extensions: ConstraintKinds, FlexibleContexts HS-Source-Dirs: src @@ -217,7 +219,6 @@ Executable ghc-mod , ghc < 7.11 , monad-control ==1.0.* , fclabels ==2.0.* - , optparse-applicative >=0.11.0 && <0.13.0 , ghc-mod Executable ghc-modi diff --git a/src/GHCMod.hs b/src/GHCMod.hs index fdade72..23e40d4 100644 --- a/src/GHCMod.hs +++ b/src/GHCMod.hs @@ -19,7 +19,7 @@ import System.Directory (setCurrentDirectory, getAppUserDataDirectory, import System.IO import System.Exit import Text.PrettyPrint hiding ((<>)) -import GHCMod.Options +import Language.Haskell.GhcMod.Options.Options import Prelude ghcModStyle :: Style From b1d123c4b6df5c4edc3c012f968b7cf8204ae06c Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Mon, 8 Feb 2016 23:02:31 +0200 Subject: [PATCH 2/8] Fix tests, export parser spec --- Language/Haskell/GhcMod/Options/Options.hs | 3 ++- test/ShellParseSpec.hs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Language/Haskell/GhcMod/Options/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs index 6f95e02..82bbda8 100644 --- a/Language/Haskell/GhcMod/Options/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -19,7 +19,8 @@ module Language.Haskell.GhcMod.Options.Options ( parseArgs, parseArgsInteractive, - GhcModCommands(..) + GhcModCommands(..), + globalArgSpec ) where import Options.Applicative diff --git a/test/ShellParseSpec.hs b/test/ShellParseSpec.hs index 2c5cefe..5111217 100644 --- a/test/ShellParseSpec.hs +++ b/test/ShellParseSpec.hs @@ -1,7 +1,7 @@ module ShellParseSpec where -import GHCMod.Options.ShellParse +import Language.Haskell.GhcMod.Options.ShellParse import Test.Hspec From 5f070b842862096b6172ae3382a5448e094985ad Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Tue, 9 Feb 2016 22:24:46 +0200 Subject: [PATCH 3/8] Rebalance between lib and exe --- Language/Haskell/GhcMod/Options/Options.hs | 45 ----------- ghc-mod.cabal | 7 +- src/GHCMod.hs | 1 + src/GHCMod/Options.hs | 77 +++++++++++++++++++ .../GhcMod => src/GHCMod}/Options/Commands.hs | 2 +- .../GHCMod}/Options/ShellParse.hs | 2 +- .../GhcMod/Options => src/GHCMod}/Version.hs | 2 +- test/ShellParseSpec.hs | 2 +- 8 files changed, 86 insertions(+), 52 deletions(-) create mode 100644 src/GHCMod/Options.hs rename {Language/Haskell/GhcMod => src/GHCMod}/Options/Commands.hs (99%) rename {Language/Haskell/GhcMod => src/GHCMod}/Options/ShellParse.hs (95%) rename {Language/Haskell/GhcMod/Options => src/GHCMod}/Version.hs (95%) diff --git a/Language/Haskell/GhcMod/Options/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs index 72cbe69..b0349f0 100644 --- a/Language/Haskell/GhcMod/Options/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -17,9 +17,6 @@ {-# OPTIONS_GHC -fno-warn-unused-do-bind #-} module Language.Haskell.GhcMod.Options.Options ( - parseArgs, - parseArgsInteractive, - GhcModCommands(..), globalArgSpec ) where @@ -30,50 +27,8 @@ import Control.Arrow import Data.Char (toUpper, toLower) import Data.List (intercalate) import Language.Haskell.GhcMod.Read -import Language.Haskell.GhcMod.Options.Commands -import Language.Haskell.GhcMod.Options.Version import Language.Haskell.GhcMod.Options.DocUtils import Language.Haskell.GhcMod.Options.Help -import Language.Haskell.GhcMod.Options.ShellParse - -parseArgs :: IO (Options, GhcModCommands) -parseArgs = - execParser opts - where - opts = info (argAndCmdSpec <**> helpVersion) - $$ fullDesc - <=> header "ghc-mod: Happy Haskell Programming" - -parseArgsInteractive :: String -> Either String GhcModCommands -parseArgsInteractive args = - handle $ execParserPure (prefs idm) opts $ parseCmdLine args - where - opts = info interactiveCommandsSpec $$ fullDesc - handle (Success a) = Right a - handle (Failure failure) = - Left $ fst $ renderFailure failure "" - handle _ = Left "Completion invoked" - -helpVersion :: Parser (a -> a) -helpVersion = - helper - <*> abortOption (InfoMsg ghcModVersion) - $$ long "version" - <=> help "Print the version of the program." - <*> argument r - $$ value id - <=> metavar "" - where - r :: ReadM (a -> a) - r = do - v <- readerAsk - case v of - "help" -> readerAbort ShowHelpText - "version" -> readerAbort $ InfoMsg ghcModVersion - _ -> return id - -argAndCmdSpec :: Parser (Options, GhcModCommands) -argAndCmdSpec = (,) <$> globalArgSpec <*> commandsSpec splitOn :: Eq a => a -> [a] -> ([a], [a]) splitOn c = second (drop 1) . break (==c) diff --git a/ghc-mod.cabal b/ghc-mod.cabal index def5ce7..1e74c23 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -154,10 +154,7 @@ Library Language.Haskell.GhcMod.World Language.Haskell.GhcMod.Options.Options - Language.Haskell.GhcMod.Options.Commands - Language.Haskell.GhcMod.Options.Version Language.Haskell.GhcMod.Options.DocUtils - Language.Haskell.GhcMod.Options.ShellParse Language.Haskell.GhcMod.Options.Help Other-Modules: Paths_ghc_mod Utils @@ -206,6 +203,9 @@ Executable ghc-mod Default-Language: Haskell2010 Main-Is: GHCMod.hs Other-Modules: Paths_ghc_mod + , GHCMod.Options.Commands + , GHCMod.Options.ShellParse + , GHCMod.Version GHC-Options: -Wall -fno-warn-deprecations -threaded Default-Extensions: ConstraintKinds, FlexibleContexts HS-Source-Dirs: src @@ -219,6 +219,7 @@ Executable ghc-mod , ghc < 7.11 , monad-control ==1.0.* , fclabels ==2.0.* + , optparse-applicative >=0.11.0 && <0.13.0 , ghc-mod Executable ghc-modi diff --git a/src/GHCMod.hs b/src/GHCMod.hs index 4a71f61..f67e9b9 100644 --- a/src/GHCMod.hs +++ b/src/GHCMod.hs @@ -20,6 +20,7 @@ import System.IO import System.Exit import Text.PrettyPrint hiding ((<>)) import Language.Haskell.GhcMod.Options.Options +import GHCMod.Options import Prelude ghcModStyle :: Style diff --git a/src/GHCMod/Options.hs b/src/GHCMod/Options.hs new file mode 100644 index 0000000..b7b13d0 --- /dev/null +++ b/src/GHCMod/Options.hs @@ -0,0 +1,77 @@ +-- ghc-mod: Making Haskell development *more* fun +-- Copyright (C) 2015 Nikolay Yakimov +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-unused-do-bind #-} + +module GHCMod.Options ( + parseArgs, + parseArgsInteractive, + GhcModCommands(..), +) where + +import Options.Applicative +import Options.Applicative.Types +import Language.Haskell.GhcMod.Types +-- import Control.Arrow +-- import Data.Char (toUpper, toLower) +-- import Data.List (intercalate) +-- import Language.Haskell.GhcMod.Read +import GHCMod.Options.Commands +import GHCMod.Version +import Language.Haskell.GhcMod.Options.DocUtils +-- import Language.Haskell.GhcMod.Options.Help +import Language.Haskell.GhcMod.Options.Options +import GHCMod.Options.ShellParse + +parseArgs :: IO (Options, GhcModCommands) +parseArgs = + execParser opts + where + opts = info (argAndCmdSpec <**> helpVersion) + $$ fullDesc + <=> header "ghc-mod: Happy Haskell Programming" + +parseArgsInteractive :: String -> Either String GhcModCommands +parseArgsInteractive args = + handle $ execParserPure (prefs idm) opts $ parseCmdLine args + where + opts = info interactiveCommandsSpec $$ fullDesc + handle (Success a) = Right a + handle (Failure failure) = + Left $ fst $ renderFailure failure "" + handle _ = Left "Completion invoked" + +helpVersion :: Parser (a -> a) +helpVersion = + helper + <*> abortOption (InfoMsg ghcModVersion) + $$ long "version" + <=> help "Print the version of the program." + <*> argument r + $$ value id + <=> metavar "" + where + r :: ReadM (a -> a) + r = do + v <- readerAsk + case v of + "help" -> readerAbort ShowHelpText + "version" -> readerAbort $ InfoMsg ghcModVersion + _ -> return id + +argAndCmdSpec :: Parser (Options, GhcModCommands) +argAndCmdSpec = (,) <$> globalArgSpec <*> commandsSpec + diff --git a/Language/Haskell/GhcMod/Options/Commands.hs b/src/GHCMod/Options/Commands.hs similarity index 99% rename from Language/Haskell/GhcMod/Options/Commands.hs rename to src/GHCMod/Options/Commands.hs index b39663a..a2ab3c0 100644 --- a/Language/Haskell/GhcMod/Options/Commands.hs +++ b/src/GHCMod/Options/Commands.hs @@ -16,7 +16,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-unused-do-bind #-} -module Language.Haskell.GhcMod.Options.Commands where +module GHCMod.Options.Commands where import Options.Applicative import Options.Applicative.Types diff --git a/Language/Haskell/GhcMod/Options/ShellParse.hs b/src/GHCMod/Options/ShellParse.hs similarity index 95% rename from Language/Haskell/GhcMod/Options/ShellParse.hs rename to src/GHCMod/Options/ShellParse.hs index a807932..acd609b 100644 --- a/Language/Haskell/GhcMod/Options/ShellParse.hs +++ b/src/GHCMod/Options/ShellParse.hs @@ -13,7 +13,7 @@ -- -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -module Language.Haskell.GhcMod.Options.ShellParse (parseCmdLine) where +module GHCMod.Options.ShellParse (parseCmdLine) where import Data.Char import Data.List diff --git a/Language/Haskell/GhcMod/Options/Version.hs b/src/GHCMod/Version.hs similarity index 95% rename from Language/Haskell/GhcMod/Options/Version.hs rename to src/GHCMod/Version.hs index 72d7371..2bf6db2 100644 --- a/Language/Haskell/GhcMod/Options/Version.hs +++ b/src/GHCMod/Version.hs @@ -14,7 +14,7 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -module Language.Haskell.GhcMod.Options.Version where +module GHCMod.Version where import Paths_ghc_mod import Data.Version (showVersion) diff --git a/test/ShellParseSpec.hs b/test/ShellParseSpec.hs index 5111217..2c5cefe 100644 --- a/test/ShellParseSpec.hs +++ b/test/ShellParseSpec.hs @@ -1,7 +1,7 @@ module ShellParseSpec where -import Language.Haskell.GhcMod.Options.ShellParse +import GHCMod.Options.ShellParse import Test.Hspec From b02dfb9ce3043e216c4ae75e778b8574c11d34d5 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Tue, 9 Feb 2016 22:34:25 +0200 Subject: [PATCH 4/8] Cleaning up --- ghc-mod.cabal | 3 ++- src/GHCMod.hs | 1 - src/GHCMod/Options.hs | 7 +------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 1e74c23..deb1a38 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -203,9 +203,10 @@ Executable ghc-mod Default-Language: Haskell2010 Main-Is: GHCMod.hs Other-Modules: Paths_ghc_mod + , GHCMod.Options , GHCMod.Options.Commands - , GHCMod.Options.ShellParse , GHCMod.Version + , GHCMod.Options.ShellParse GHC-Options: -Wall -fno-warn-deprecations -threaded Default-Extensions: ConstraintKinds, FlexibleContexts HS-Source-Dirs: src diff --git a/src/GHCMod.hs b/src/GHCMod.hs index f67e9b9..531f7de 100644 --- a/src/GHCMod.hs +++ b/src/GHCMod.hs @@ -19,7 +19,6 @@ import System.Directory (setCurrentDirectory, getAppUserDataDirectory, import System.IO import System.Exit import Text.PrettyPrint hiding ((<>)) -import Language.Haskell.GhcMod.Options.Options import GHCMod.Options import Prelude diff --git a/src/GHCMod/Options.hs b/src/GHCMod/Options.hs index b7b13d0..c3cf263 100644 --- a/src/GHCMod/Options.hs +++ b/src/GHCMod/Options.hs @@ -19,20 +19,15 @@ module GHCMod.Options ( parseArgs, parseArgsInteractive, - GhcModCommands(..), + GhcModCommands(..) ) where import Options.Applicative import Options.Applicative.Types import Language.Haskell.GhcMod.Types --- import Control.Arrow --- import Data.Char (toUpper, toLower) --- import Data.List (intercalate) --- import Language.Haskell.GhcMod.Read import GHCMod.Options.Commands import GHCMod.Version import Language.Haskell.GhcMod.Options.DocUtils --- import Language.Haskell.GhcMod.Options.Help import Language.Haskell.GhcMod.Options.Options import GHCMod.Options.ShellParse From 85df08a91312098173c3450ee0250ab88beb39d3 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Mon, 15 Feb 2016 22:04:47 +0200 Subject: [PATCH 5/8] 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. --- Language/Haskell/GhcMod/Options/Options.hs | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Language/Haskell/GhcMod/Options/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs index b0349f0..8d10d9d 100644 --- a/Language/Haskell/GhcMod/Options/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -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 From 45eb3b8d4c0dd4857e9b7c6c9044a4d2c95db586 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Mon, 29 Feb 2016 20:45:32 +0200 Subject: [PATCH 6/8] Do not use deprecated API for parseCmdLineOptions Thanks to @lierdakil --- Language/Haskell/GhcMod/Options/Options.hs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Language/Haskell/GhcMod/Options/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs index 8d10d9d..c49d6f7 100644 --- a/Language/Haskell/GhcMod/Options/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -35,18 +35,7 @@ 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 - } +parseCmdLineOptions = getParseResult . execParserPure (prefs mempty) (info globalArgSpec mempty) splitOn :: Eq a => a -> [a] -> ([a], [a]) splitOn c = second (drop 1) . break (==c) From 04b75e2bdef561ab53b1068673ff66f8c2fb6084 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Mon, 29 Feb 2016 21:24:30 +0200 Subject: [PATCH 7/8] Sort out imports for earlier GHC versions --- Language/Haskell/GhcMod/Options/Options.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Language/Haskell/GhcMod/Options/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs index c49d6f7..8b13091 100644 --- a/Language/Haskell/GhcMod/Options/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} -- ghc-mod: Making Haskell development *more* fun -- Copyright (C) 2015 Nikolay Yakimov -- @@ -22,12 +23,14 @@ module Language.Haskell.GhcMod.Options.Options ( ) where import Options.Applicative -import Options.Applicative.Help.Chunk import Options.Applicative.Types import Language.Haskell.GhcMod.Types import Control.Arrow import Data.Char (toUpper, toLower) import Data.List (intercalate) +#if __GLASGOW_HASKELL__ < 710 +import Data.Monoid (mempty) +#endif import Language.Haskell.GhcMod.Read import Language.Haskell.GhcMod.Options.DocUtils import Language.Haskell.GhcMod.Options.Help From f992200d57fc93355d5e5c754ce7b65ee701cfc3 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Tue, 1 Mar 2016 22:58:10 +0200 Subject: [PATCH 8/8] Remove CPP from Options As per @lierdakil suggestion --- Language/Haskell/GhcMod/Options/Options.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Language/Haskell/GhcMod/Options/Options.hs b/Language/Haskell/GhcMod/Options/Options.hs index 8b13091..7d4aa3a 100644 --- a/Language/Haskell/GhcMod/Options/Options.hs +++ b/Language/Haskell/GhcMod/Options/Options.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} -- ghc-mod: Making Haskell development *more* fun -- Copyright (C) 2015 Nikolay Yakimov -- @@ -28,12 +27,11 @@ import Language.Haskell.GhcMod.Types import Control.Arrow import Data.Char (toUpper, toLower) import Data.List (intercalate) -#if __GLASGOW_HASKELL__ < 710 -import Data.Monoid (mempty) -#endif import Language.Haskell.GhcMod.Read import Language.Haskell.GhcMod.Options.DocUtils import Language.Haskell.GhcMod.Options.Help +import Data.Monoid +import Prelude -- | Parse a set of arguments according to the ghc-mod CLI flag spec, producing -- @Options@ set accordingly.