From 94318988e05f17c1200dbb1730a0def3264a67f1 Mon Sep 17 00:00:00 2001 From: Alexis Williams Date: Thu, 12 Jul 2018 13:45:48 -0700 Subject: [PATCH 1/2] Add aliases for new- commands that won't change at any point. --- .../Distribution/Client/CmdLegacy.hs | 14 ++++++++- cabal-install/Distribution/Client/Setup.hs | 30 +++++++++++++++++++ cabal-install/main/Main.hs | 29 +++++++++--------- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdLegacy.hs b/cabal-install/Distribution/Client/CmdLegacy.hs index d8fc4b23eed..d93b6e2ff17 100644 --- a/cabal-install/Distribution/Client/CmdLegacy.hs +++ b/cabal-install/Distribution/Client/CmdLegacy.hs @@ -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 @@ -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 + } diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 5e65011e88d..9b4073612bc 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -203,6 +203,7 @@ globalCommand commands = CommandUI { , "new-install" , "new-clean" , "new-sdist" + -- v1 commands, stateful style , "v1-build" , "v1-configure" , "v1-repl" @@ -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) ' ' @@ -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" diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index 8c8ceb8874c..fdb608f48af 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -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 From a83fc6d83855caafaf561ebae0c91fcafc0814c9 Mon Sep 17 00:00:00 2001 From: Alexis Williams Date: Thu, 12 Jul 2018 13:54:33 -0700 Subject: [PATCH 2/2] Add docs [ci skip] --- Cabal/doc/nix-local-build-overview.rst | 6 +++++- cabal-install/changelog | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cabal/doc/nix-local-build-overview.rst b/Cabal/doc/nix-local-build-overview.rst index c581b9ef40f..736ae4d26b8 100644 --- a/Cabal/doc/nix-local-build-overview.rst +++ b/Cabal/doc/nix-local-build-overview.rst @@ -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: diff --git a/cabal-install/changelog b/cabal-install/changelog index cf9defae1c0..c170ad2ae5d 100644 --- a/cabal-install/changelog +++ b/cabal-install/changelog @@ -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