Rebalance between lib and exe
This commit is contained in:
parent
d47c9f1205
commit
5f070b8428
@ -17,9 +17,6 @@
|
|||||||
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
|
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
|
||||||
|
|
||||||
module Language.Haskell.GhcMod.Options.Options (
|
module Language.Haskell.GhcMod.Options.Options (
|
||||||
parseArgs,
|
|
||||||
parseArgsInteractive,
|
|
||||||
GhcModCommands(..),
|
|
||||||
globalArgSpec
|
globalArgSpec
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -30,50 +27,8 @@ import Control.Arrow
|
|||||||
import Data.Char (toUpper, toLower)
|
import Data.Char (toUpper, toLower)
|
||||||
import Data.List (intercalate)
|
import Data.List (intercalate)
|
||||||
import Language.Haskell.GhcMod.Read
|
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.DocUtils
|
||||||
import Language.Haskell.GhcMod.Options.Help
|
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 :: Eq a => a -> [a] -> ([a], [a])
|
||||||
splitOn c = second (drop 1) . break (==c)
|
splitOn c = second (drop 1) . break (==c)
|
||||||
|
@ -154,10 +154,7 @@ Library
|
|||||||
Language.Haskell.GhcMod.World
|
Language.Haskell.GhcMod.World
|
||||||
|
|
||||||
Language.Haskell.GhcMod.Options.Options
|
Language.Haskell.GhcMod.Options.Options
|
||||||
Language.Haskell.GhcMod.Options.Commands
|
|
||||||
Language.Haskell.GhcMod.Options.Version
|
|
||||||
Language.Haskell.GhcMod.Options.DocUtils
|
Language.Haskell.GhcMod.Options.DocUtils
|
||||||
Language.Haskell.GhcMod.Options.ShellParse
|
|
||||||
Language.Haskell.GhcMod.Options.Help
|
Language.Haskell.GhcMod.Options.Help
|
||||||
Other-Modules: Paths_ghc_mod
|
Other-Modules: Paths_ghc_mod
|
||||||
Utils
|
Utils
|
||||||
@ -206,6 +203,9 @@ Executable ghc-mod
|
|||||||
Default-Language: Haskell2010
|
Default-Language: Haskell2010
|
||||||
Main-Is: GHCMod.hs
|
Main-Is: GHCMod.hs
|
||||||
Other-Modules: Paths_ghc_mod
|
Other-Modules: Paths_ghc_mod
|
||||||
|
, GHCMod.Options.Commands
|
||||||
|
, GHCMod.Options.ShellParse
|
||||||
|
, GHCMod.Version
|
||||||
GHC-Options: -Wall -fno-warn-deprecations -threaded
|
GHC-Options: -Wall -fno-warn-deprecations -threaded
|
||||||
Default-Extensions: ConstraintKinds, FlexibleContexts
|
Default-Extensions: ConstraintKinds, FlexibleContexts
|
||||||
HS-Source-Dirs: src
|
HS-Source-Dirs: src
|
||||||
@ -219,6 +219,7 @@ Executable ghc-mod
|
|||||||
, ghc < 7.11
|
, ghc < 7.11
|
||||||
, monad-control ==1.0.*
|
, monad-control ==1.0.*
|
||||||
, fclabels ==2.0.*
|
, fclabels ==2.0.*
|
||||||
|
, optparse-applicative >=0.11.0 && <0.13.0
|
||||||
, ghc-mod
|
, ghc-mod
|
||||||
|
|
||||||
Executable ghc-modi
|
Executable ghc-modi
|
||||||
|
@ -20,6 +20,7 @@ import System.IO
|
|||||||
import System.Exit
|
import System.Exit
|
||||||
import Text.PrettyPrint hiding ((<>))
|
import Text.PrettyPrint hiding ((<>))
|
||||||
import Language.Haskell.GhcMod.Options.Options
|
import Language.Haskell.GhcMod.Options.Options
|
||||||
|
import GHCMod.Options
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
ghcModStyle :: Style
|
ghcModStyle :: Style
|
||||||
|
77
src/GHCMod/Options.hs
Normal file
77
src/GHCMod/Options.hs
Normal 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
|
||||||
|
|
@ -16,7 +16,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
|
{-# 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
|
||||||
import Options.Applicative.Types
|
import Options.Applicative.Types
|
@ -13,7 +13,7 @@
|
|||||||
--
|
--
|
||||||
-- You should have received a copy of the GNU Affero General Public License
|
-- 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/>.
|
-- 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.Char
|
||||||
import Data.List
|
import Data.List
|
@ -14,7 +14,7 @@
|
|||||||
-- You should have received a copy of the GNU Affero General Public License
|
-- 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/>.
|
-- 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 Paths_ghc_mod
|
||||||
import Data.Version (showVersion)
|
import Data.Version (showVersion)
|
@ -1,7 +1,7 @@
|
|||||||
module ShellParseSpec where
|
module ShellParseSpec where
|
||||||
|
|
||||||
|
|
||||||
import Language.Haskell.GhcMod.Options.ShellParse
|
import GHCMod.Options.ShellParse
|
||||||
|
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user