Skip to content

Add future-proof aliases for new- commands #5429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cabal/doc/nix-local-build-overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ names are only temporary until Nix-style local builds become the default.
This is expected to happen soon. For those who do not wish to use the new
functionality, the classic project style will not be removed immediately,
but these legacy commands will require the usage of the ``v1-`` prefix as of
Cabal 3.0 and will be removed in a future release.
Cabal 3.0 and will be removed in a future release. For a future-proof
way to use these commands in a script or tutorial that anticipates the
possibility of another UI paradigm being devised in the future, there
are also ``v2-`` prefixed versions that will reference the same functionality
until such a point as it is completely removed from Cabal.

Nix-style local builds combine the best of non-sandboxed and sandboxed Cabal:

Expand Down
14 changes: 13 additions & 1 deletion cabal-install/Distribution/Client/CmdLegacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
module Distribution.Client.CmdLegacy ( legacyCmd, legacyWrapperCmd ) where
module Distribution.Client.CmdLegacy ( legacyCmd, legacyWrapperCmd, newCmd ) where

import Prelude ()
import Distribution.Client.Compat.Prelude
Expand Down Expand Up @@ -159,3 +159,15 @@ legacyCmd ui action = toLegacyCmd (regularCmd ui action)

legacyWrapperCmd :: Monoid flags => CommandUI flags -> (flags -> Setup.Flag Verbosity) -> (flags -> Setup.Flag String) -> [CommandSpec (Client.GlobalFlags -> IO ())]
legacyWrapperCmd ui verbosity' distPref = toLegacyCmd (wrapperCmd ui verbosity' distPref)

newCmd :: CommandUI flags -> (flags -> [String] -> globals -> IO action) -> [CommandSpec (globals -> IO action)]
newCmd origUi@CommandUI{..} action = [cmd v2Ui, cmd origUi]
where
cmd ui = CommandSpec ui (flip commandAddAction action) NormalCommand
v2Msg = T.unpack . T.replace "new-" "v2-" . T.pack
v2Ui = origUi
{ commandName = v2Msg commandName
, commandUsage = v2Msg . commandUsage
, commandDescription = (v2Msg .) <$> commandDescription
, commandNotes = (v2Msg .) <$> commandDescription
}
30 changes: 30 additions & 0 deletions cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ globalCommand commands = CommandUI {
, "new-install"
, "new-clean"
, "new-sdist"
-- v1 commands, stateful style
, "v1-build"
, "v1-configure"
, "v1-repl"
Expand All @@ -221,6 +222,20 @@ globalCommand commands = CommandUI {
, "v1-register"
, "v1-reconfigure"
, "v1-sandbox"
-- v2 commands, nix-style
, "v2-build"
, "v2-configure"
, "v2-repl"
, "v2-freeze"
, "v2-run"
, "v2-test"
, "v2-bench"
, "v2-haddock"
, "v2-exec"
, "v2-update"
, "v2-install"
, "v2-clean"
, "v2-sdist"
]
maxlen = maximum $ [length name | (name, _) <- cmdDescs]
align str = str ++ replicate (maxlen - length str) ' '
Expand Down Expand Up @@ -294,6 +309,21 @@ globalCommand commands = CommandUI {
, addCmd "new-clean"
, addCmd "new-sdist"
, par
, startGroup "new-style projects (forwards-compatible aliases)"
, addCmd "v2-build"
, addCmd "v2-configure"
, addCmd "v2-repl"
, addCmd "v2-run"
, addCmd "v2-test"
, addCmd "v2-bench"
, addCmd "v2-freeze"
, addCmd "v2-haddock"
, addCmd "v2-exec"
, addCmd "v2-update"
, addCmd "v2-install"
, addCmd "v2-clean"
, addCmd "v2-sdist"
, par
, startGroup "legacy command aliases"
, addCmd "v1-build"
, addCmd "v1-configure"
Expand Down
9 changes: 6 additions & 3 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
-*-change-log-*-

2.4.0.0 (current development version)
* 'outdated' now accepts '--project-file FILE', which will look for bounds
from the new-style freeze file named FILE.freeze. This is only
available when `--new-freeze-file` has been passed.
* Add aliases for the "new-" commands that won't change when they
lose their prefix or are eventually replaced by a third UI
paradigm in the future. (#5429)
* 'outdated' now accepts '--project-file FILE', which will look for bounds
from the new-style freeze file named FILE.freeze. This is only
available when `--new-freeze-file` has been passed.
* 'new-repl' now accepts a '--build-depends' flag which accepts the
same syntax as is used in .cabal files to add additional dependencies
to the environment when developing in the REPL. It is now usable outside
Expand Down
29 changes: 15 additions & 14 deletions cabal-install/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,22 @@ mainWorker args = topHandler $
, hiddenCmd actAsSetupCommand actAsSetupAction
, hiddenCmd manpageCommand (manpageAction commandSpecs)

, regularCmd CmdConfigure.configureCommand CmdConfigure.configureAction
, regularCmd CmdUpdate.updateCommand CmdUpdate.updateAction
, regularCmd CmdBuild.buildCommand CmdBuild.buildAction
, regularCmd CmdRepl.replCommand CmdRepl.replAction
, regularCmd CmdFreeze.freezeCommand CmdFreeze.freezeAction
, regularCmd CmdHaddock.haddockCommand CmdHaddock.haddockAction
, regularCmd CmdInstall.installCommand CmdInstall.installAction
, regularCmd CmdRun.runCommand CmdRun.runAction
, regularCmd CmdTest.testCommand CmdTest.testAction
, regularCmd CmdBench.benchCommand CmdBench.benchAction
, regularCmd CmdExec.execCommand CmdExec.execAction
, regularCmd CmdClean.cleanCommand CmdClean.cleanAction
, regularCmd CmdSdist.sdistCommand CmdSdist.sdistAction
] ++ concat
[ legacyCmd configureExCommand configureAction
[ newCmd CmdConfigure.configureCommand CmdConfigure.configureAction
, newCmd CmdUpdate.updateCommand CmdUpdate.updateAction
, newCmd CmdBuild.buildCommand CmdBuild.buildAction
, newCmd CmdRepl.replCommand CmdRepl.replAction
, newCmd CmdFreeze.freezeCommand CmdFreeze.freezeAction
, newCmd CmdHaddock.haddockCommand CmdHaddock.haddockAction
, newCmd CmdInstall.installCommand CmdInstall.installAction
, newCmd CmdRun.runCommand CmdRun.runAction
, newCmd CmdTest.testCommand CmdTest.testAction
, newCmd CmdBench.benchCommand CmdBench.benchAction
, newCmd CmdExec.execCommand CmdExec.execAction
, newCmd CmdClean.cleanCommand CmdClean.cleanAction
, newCmd CmdSdist.sdistCommand CmdSdist.sdistAction

, legacyCmd configureExCommand configureAction
, legacyCmd updateCommand updateAction
, legacyCmd buildCommand buildAction
, legacyCmd replCommand replAction
Expand Down