Skip to content

Commit

Permalink
Introduce applyFlagsDefault and use ViewPatterns
Browse files Browse the repository at this point in the history
(cherry picked from commit 71131cf)
  • Loading branch information
Alexander Biehl authored and 23Skidoo committed Aug 2, 2017
1 parent 387d443 commit 41a4ef1
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 25 deletions.
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Client/CmdBench.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ViewPatterns #-}

-- | cabal-install CLI command: bench
--
Expand All @@ -17,7 +18,8 @@ import Distribution.Client.ProjectOrchestration
import Distribution.Client.CmdErrorMessages

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import qualified Distribution.Client.Setup as Client
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
Expand Down Expand Up @@ -75,7 +77,7 @@ benchCommand = Client.installCommand {
--
benchAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
benchAction (configFlags, configExFlags, installFlags, haddockFlags)
benchAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
targetStrings globalFlags = do

baseCtx <- establishProjectBaseContext verbosity cliConfig
Expand Down
7 changes: 5 additions & 2 deletions cabal-install/Distribution/Client/CmdBuild.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE ViewPatterns #-}

-- | cabal-install CLI command: build
--
module Distribution.Client.CmdBuild (
Expand All @@ -15,7 +17,8 @@ import Distribution.Client.ProjectOrchestration
import Distribution.Client.CmdErrorMessages

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import qualified Distribution.Client.Setup as Client
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
Expand Down Expand Up @@ -72,7 +75,7 @@ buildCommand = Client.installCommand {
--
buildAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
buildAction (configFlags, configExFlags, installFlags, haddockFlags)
buildAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
targetStrings globalFlags = do

baseCtx <- establishProjectBaseContext verbosity cliConfig
Expand Down
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Client/CmdConfigure.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE ViewPatterns #-}
-- | cabal-install CLI command: configure
--
module Distribution.Client.CmdConfigure (
Expand All @@ -10,7 +11,8 @@ import Distribution.Client.ProjectConfig
( writeProjectLocalExtraConfig )

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
import Distribution.Verbosity
Expand Down Expand Up @@ -76,7 +78,7 @@ configureCommand = Client.installCommand {
--
configureAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
configureAction (configFlags, configExFlags, installFlags, haddockFlags)
configureAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
_extraArgs globalFlags = do
--TODO: deal with _extraArgs, since flags with wrong syntax end up there

Expand Down
7 changes: 4 additions & 3 deletions cabal-install/Distribution/Client/CmdFreeze.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE CPP, NamedFieldPuns, RecordWildCards #-}
{-# LANGUAGE CPP, NamedFieldPuns, RecordWildCards, ViewPatterns #-}

-- | cabal-install CLI command: freeze
--
Expand Down Expand Up @@ -31,7 +31,8 @@ import Distribution.Version
import Distribution.PackageDescription
( FlagAssignment )
import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
import Distribution.Simple.Utils
Expand Down Expand Up @@ -103,7 +104,7 @@ freezeCommand = Client.installCommand {
--
freezeAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
freezeAction (configFlags, configExFlags, installFlags, haddockFlags)
freezeAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
extraArgs globalFlags = do

unless (null extraArgs) $
Expand Down
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Client/CmdHaddock.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ViewPatterns #-}

-- | cabal-install CLI command: haddock
--
Expand All @@ -17,7 +18,8 @@ import Distribution.Client.ProjectOrchestration
import Distribution.Client.CmdErrorMessages

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import qualified Distribution.Client.Setup as Client
import Distribution.Simple.Setup
( HaddockFlags(..), fromFlagOrDefault, fromFlag )
Expand Down Expand Up @@ -71,7 +73,7 @@ haddockCommand = Client.installCommand {
--
haddockAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
haddockAction (configFlags, configExFlags, installFlags, haddockFlags)
haddockAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
targetStrings globalFlags = do

baseCtx <- establishProjectBaseContext verbosity cliConfig
Expand Down
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Client/CmdRepl.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ViewPatterns #-}

-- | cabal-install CLI command: repl
--
Expand All @@ -17,7 +18,8 @@ import Distribution.Client.ProjectOrchestration
import Distribution.Client.CmdErrorMessages

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import qualified Distribution.Client.Setup as Client
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
Expand Down Expand Up @@ -87,7 +89,7 @@ replCommand = Client.installCommand {
--
replAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
replAction (configFlags, configExFlags, installFlags, haddockFlags)
replAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
targetStrings globalFlags = do

baseCtx <- establishProjectBaseContext verbosity cliConfig
Expand Down
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Client/CmdRun.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ViewPatterns #-}

-- | cabal-install CLI command: run
--
Expand All @@ -17,7 +18,8 @@ import Distribution.Client.ProjectOrchestration
import Distribution.Client.CmdErrorMessages

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import qualified Distribution.Client.Setup as Client
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
Expand Down Expand Up @@ -84,7 +86,7 @@ runCommand = Client.installCommand {
--
runAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
runAction (configFlags, configExFlags, installFlags, haddockFlags)
runAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
targetStrings globalFlags = do

baseCtx <- establishProjectBaseContext verbosity cliConfig
Expand Down
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Client/CmdTest.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ViewPatterns #-}

-- | cabal-install CLI command: test
--
Expand All @@ -17,7 +18,8 @@ import Distribution.Client.ProjectOrchestration
import Distribution.Client.CmdErrorMessages

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags
, applyFlagDefaults )
import qualified Distribution.Client.Setup as Client
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
Expand Down Expand Up @@ -78,7 +80,7 @@ testCommand = Client.installCommand {
--
testAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
testAction (configFlags, configExFlags, installFlags, haddockFlags)
testAction (applyFlagDefaults -> (configFlags, configExFlags, installFlags, haddockFlags))
targetStrings globalFlags = do

baseCtx <- establishProjectBaseContext verbosity cliConfig
Expand Down
20 changes: 12 additions & 8 deletions cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module Distribution.Client.Setup
, userConfigCommand, UserConfigFlags(..)
, manpageCommand

, applyFlagDefaults
, parsePackageArgs
--TODO: stop exporting these:
, showRepo
Expand Down Expand Up @@ -128,6 +129,15 @@ import System.FilePath
import Network.URI
( parseAbsoluteURI, uriToString )

applyFlagDefaults :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
applyFlagDefaults (configFlags, configExFlags, installFlags, haddockFlags) =
( commandDefaultFlags configureCommand <> configFlags
, defaultConfigExFlags <> configExFlags
, defaultInstallFlags <> installFlags
, Cabal.defaultHaddockFlags <> haddockFlags
)

globalCommand :: [Command action] -> CommandUI GlobalFlags
globalCommand commands = CommandUI {
commandName = "",
Expand Down Expand Up @@ -1023,10 +1033,7 @@ upgradeCommand = configureCommand {
commandSynopsis = "(command disabled, use install instead)",
commandDescription = Nothing,
commandUsage = usageFlagsOrPackages "upgrade",
commandDefaultFlags = (commandDefaultFlags configureCommand,
defaultConfigExFlags,
defaultInstallFlags,
Cabal.defaultHaddockFlags),
commandDefaultFlags = (mempty, mempty, mempty, mempty),
commandOptions = commandOptions installCommand
}

Expand Down Expand Up @@ -1533,10 +1540,7 @@ installCommand = CommandUI {
++ " " ++ (map (const ' ') pname)
++ " "
++ " Change installation destination\n",
commandDefaultFlags = (commandDefaultFlags configureCommand,
defaultConfigExFlags,
defaultInstallFlags,
Cabal.defaultHaddockFlags),
commandDefaultFlags = (mempty, mempty, mempty, mempty),
commandOptions = \showOrParseArgs ->
liftOptions get1 set1
(filter ((`notElem` ["constraint", "dependency"
Expand Down

0 comments on commit 41a4ef1

Please sign in to comment.