Rebalance between lib and exe

This commit is contained in:
Alan Zimmerman 2016-02-09 22:24:46 +02:00
parent d47c9f1205
commit 5f070b8428
8 changed files with 86 additions and 52 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

77
src/GHCMod/Options.hs Normal file
View File

@ -0,0 +1,77 @@
-- ghc-mod: Making Haskell development *more* fun
-- Copyright (C) 2015 Nikolay Yakimov <root@livid.pp.ru>
--
-- 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 <http://www.gnu.org/licenses/>.
{-# 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

View File

@ -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

View File

@ -13,7 +13,7 @@
--
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
module Language.Haskell.GhcMod.Options.ShellParse (parseCmdLine) where
module GHCMod.Options.ShellParse (parseCmdLine) where
import Data.Char
import Data.List

View File

@ -14,7 +14,7 @@
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
module Language.Haskell.GhcMod.Options.Version where
module GHCMod.Version where
import Paths_ghc_mod
import Data.Version (showVersion)

View File

@ -1,7 +1,7 @@
module ShellParseSpec where
import Language.Haskell.GhcMod.Options.ShellParse
import GHCMod.Options.ShellParse
import Test.Hspec