Skip to content

Commit 64d5b92

Browse files
committed
Take n+1, filtering rather than adding v1-
1 parent 12de975 commit 64d5b92

File tree

3 files changed

+150
-54
lines changed

3 files changed

+150
-54
lines changed
Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE FlexibleInstances #-}
23
{-# LANGUAGE RecordWildCards #-}
34
{-# LANGUAGE ViewPatterns #-}
45
module Distribution.Client.CmdLegacy (legacyCmd) where
56

67
import Prelude ()
78
import Distribution.Client.Compat.Prelude
89

10+
import qualified Distribution.Client.Setup as Client
11+
import qualified Distribution.Simple.Setup as Setup
912
import Distribution.Simple.Command
1013
import Distribution.Simple.Utils
1114
( warn )
1215
import Distribution.Verbosity
13-
( normal )
16+
( Verbosity, normal )
1417

1518
import qualified Data.Text as T
1619

@@ -28,46 +31,67 @@ deprecationNote cmd =
2831
"cabal-install. Please file a bug if you cannot replicate a working v1- use\n" ++
2932
"case with the new-style commands.\n"
3033

34+
--
3135

32-
oldCommands :: [(T.Text, T.Text)]
33-
oldCommands = (\c -> (c, "v1-" `T.append` c)) <$> cmds
34-
where
35-
cmds =
36-
[ "build"
37-
, "configure"
38-
, "repl"
39-
, "freeze"
40-
, "run"
41-
, "test"
42-
, "bench"
43-
, "haddock"
44-
, "exec"
45-
, "update"
46-
, "install"
47-
]
48-
49-
legacyCmd :: CommandUI flags -> (flags -> [String] -> globals -> IO action) -> [CommandSpec (globals -> IO action)]
36+
class HasVerbosity a where
37+
verbosity :: a -> Verbosity
38+
39+
instance HasVerbosity (Setup.Flag Verbosity) where
40+
verbosity = Setup.fromFlagOrDefault normal
41+
42+
instance (HasVerbosity a) => HasVerbosity (a, b) where
43+
verbosity (a, _) = verbosity a
44+
45+
instance (HasVerbosity b) => HasVerbosity (a, b, c) where
46+
verbosity (_ , b, _) = verbosity b
47+
48+
instance (HasVerbosity a) => HasVerbosity (a, b, c, d) where
49+
verbosity (a, _, _, _) = verbosity a
50+
51+
instance HasVerbosity Setup.BuildFlags where
52+
verbosity = verbosity . Setup.buildVerbosity
53+
54+
instance HasVerbosity Setup.ConfigFlags where
55+
verbosity = verbosity . Setup.configVerbosity
56+
57+
instance HasVerbosity Setup.ReplFlags where
58+
verbosity = verbosity . Setup.replVerbosity
59+
60+
instance HasVerbosity Client.FreezeFlags where
61+
verbosity = verbosity . Client.freezeVerbosity
62+
63+
instance HasVerbosity Setup.HaddockFlags where
64+
verbosity = verbosity . Setup.haddockVerbosity
65+
66+
instance HasVerbosity Client.ExecFlags where
67+
verbosity = verbosity . Client.execVerbosity
68+
69+
instance HasVerbosity Client.UpdateFlags where
70+
verbosity = verbosity . Client.updateVerbosity
71+
72+
--
73+
74+
legacyCmd :: (HasVerbosity flags) => CommandUI flags -> (flags -> [String] -> globals -> IO action) -> [CommandSpec (globals -> IO action)]
5075
legacyCmd origUi@CommandUI{..} action = [makeCmd legacyUi legacyAction, makeCmd aliasedUi action]
5176
where
52-
updateMsg msg = T.unpack $ foldr (\(old, new) str -> T.replace old new str) (T.pack msg) oldCommands
53-
54-
legacyMsg msg = T.unpack $ foldr (\(new, old) str -> T.replace old new str) (T.pack msg) oldCommands
77+
legacyMsg = T.unpack . T.replace "v1-" "" . T.pack
5578

5679
note = deprecationNote commandName
5780

58-
legacyAction flags extra globals = warn normal (note ++ "\n") >> action flags extra globals
81+
legacyAction flags extra globals = warn (verbosity flags) (note ++ "\n") >> action flags extra globals
5982

60-
legacyUi = origUi
61-
{ commandNotes = Just $ \pname -> case commandNotes of
62-
Just notes -> legacyMsg (notes pname) ++ "\n" ++ note
83+
aliasedUi = origUi
84+
{ commandName = "v1-" ++ commandName
85+
, commandNotes = Just $ \pname -> case commandNotes of
86+
Just notes -> notes pname ++ "\n" ++ note
6387
Nothing -> note
6488
}
6589

66-
aliasedUi = origUi
67-
{ commandName = updateMsg commandName
68-
, commandUsage = updateMsg . commandUsage
69-
, commandDescription = (updateMsg .) <$> commandDescription
90+
legacyUi = origUi
91+
{ commandName = legacyMsg commandName
92+
, commandUsage = legacyMsg . commandUsage
93+
, commandDescription = (legacyMsg .) <$> commandDescription
7094
, commandNotes = Just $ \pname -> case commandNotes of
71-
Just notes -> notes pname ++ "\n" ++ note
95+
Just notes -> legacyMsg (notes pname) ++ "\n" ++ note
7296
Nothing -> note
7397
}

cabal-install/Distribution/Client/Setup.hs

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module Distribution.Client.Setup
4949
, execCommand, ExecFlags(..), defaultExecFlags
5050
, userConfigCommand, UserConfigFlags(..)
5151
, manpageCommand
52+
, haddockCommand
5253

5354
, parsePackageArgs
5455
--TODO: stop exporting these:
@@ -402,15 +403,24 @@ globalCommand commands = CommandUI {
402403

403404
configureCommand :: CommandUI ConfigFlags
404405
configureCommand = c
405-
{ commandDefaultFlags = mempty
406+
{ commandName = "v1-configure"
407+
, commandDefaultFlags = mempty
408+
, commandDescription = Just $ \_ -> wrapText $
409+
"Configure how the package is built by setting "
410+
++ "package (and other) flags.\n"
411+
++ "\n"
412+
++ "The configuration affects several other commands, "
413+
++ "including v1-build, v1-test, v1-bench, v1-run, v1-repl.\n"
414+
, commandUsage = \pname ->
415+
"Usage: " ++ pname ++ " v1-configure [FLAGS]\n"
406416
, commandNotes = Just $ \pname ->
407-
(Cabal.programFlagsDescription defaultProgramDb ++ "\n")
408-
++ "Examples:\n"
409-
++ " " ++ pname ++ " v1-configure\n"
410-
++ " Configure with defaults;\n"
411-
++ " " ++ pname ++ " v1-configure --enable-tests -fcustomflag\n"
412-
++ " Configure building package including tests,\n"
413-
++ " with some package-specific flag.\n"
417+
(Cabal.programFlagsDescription defaultProgramDb ++ "\n")
418+
++ "Examples:\n"
419+
++ " " ++ pname ++ " v1-configure\n"
420+
++ " Configure with defaults;\n"
421+
++ " " ++ pname ++ " v1-configure --enable-tests -fcustomflag\n"
422+
++ " Configure building package including tests,\n"
423+
++ " with some package-specific flag.\n"
414424
}
415425
where
416426
c = Cabal.configureCommand defaultProgramDb
@@ -680,7 +690,14 @@ buildExOptions _showOrParseArgs =
680690

681691
buildCommand :: CommandUI (BuildFlags, BuildExFlags)
682692
buildCommand = parent {
693+
commandName = "build",
694+
commandDescription = Just $ \_ -> wrapText $
695+
"Components encompass executables, tests, and benchmarks.\n"
696+
++ "\n"
697+
++ "Affected by configuration options, see `v1-configure`.\n",
683698
commandDefaultFlags = (commandDefaultFlags parent, mempty),
699+
commandUsage = usageAlternatives "v1-build" $
700+
[ "[FLAGS]", "COMPONENTS [FLAGS]" ],
684701
commandOptions =
685702
\showOrParseArgs -> liftOptions fst setFst
686703
(commandOptions parent showOrParseArgs)
@@ -713,6 +730,26 @@ instance Semigroup BuildExFlags where
713730

714731
replCommand :: CommandUI (ReplFlags, BuildExFlags)
715732
replCommand = parent {
733+
commandName = "repl",
734+
commandDescription = Just $ \pname -> wrapText $
735+
"If the current directory contains no package, ignores COMPONENT "
736+
++ "parameters and opens an interactive interpreter session; if a "
737+
++ "sandbox is present, its package database will be used.\n"
738+
++ "\n"
739+
++ "Otherwise, (re)configures with the given or default flags, and "
740+
++ "loads the interpreter with the relevant modules. For executables, "
741+
++ "tests and benchmarks, loads the main module (and its "
742+
++ "dependencies); for libraries all exposed/other modules.\n"
743+
++ "\n"
744+
++ "The default component is the library itself, or the executable "
745+
++ "if that is the only component.\n"
746+
++ "\n"
747+
++ "Support for loading specific modules is planned but not "
748+
++ "implemented yet. For certain scenarios, `" ++ pname
749+
++ " v1-exec -- ghci :l Foo` may be used instead. Note that `v1-exec` will "
750+
++ "not (re)configure and you will have to specify the location of "
751+
++ "other modules, if required.\n",
752+
commandUsage = \pname -> "Usage: " ++ pname ++ " v1-repl [COMPONENT] [FLAGS]\n",
716753
commandDefaultFlags = (commandDefaultFlags parent, mempty),
717754
commandOptions =
718755
\showOrParseArgs -> liftOptions fst setFst
@@ -740,6 +777,19 @@ replCommand = parent {
740777

741778
testCommand :: CommandUI (TestFlags, BuildFlags, BuildExFlags)
742779
testCommand = parent {
780+
commandName = "test",
781+
commandDescription = Just $ \pname -> wrapText $
782+
"If necessary (re)configures with `--enable-tests` flag and builds"
783+
++ " the test suite.\n"
784+
++ "\n"
785+
++ "Remember that the tests' dependencies must be installed if there"
786+
++ " are additional ones; e.g. with `" ++ pname
787+
++ " v1-install --only-dependencies --enable-tests`.\n"
788+
++ "\n"
789+
++ "By defining UserHooks in a custom Setup.hs, the package can"
790+
++ " define actions to be executed before and after running tests.\n",
791+
commandUsage = usageAlternatives "v1-test"
792+
[ "[FLAGS]", "TESTCOMPONENTS [FLAGS]" ],
743793
commandDefaultFlags = (commandDefaultFlags parent,
744794
Cabal.defaultBuildFlags, mempty),
745795
commandOptions =
@@ -765,6 +815,20 @@ testCommand = parent {
765815

766816
benchmarkCommand :: CommandUI (BenchmarkFlags, BuildFlags, BuildExFlags)
767817
benchmarkCommand = parent {
818+
commandName = "bench",
819+
commandUsage = usageAlternatives "v1-bench"
820+
[ "[FLAGS]", "BENCHCOMPONENTS [FLAGS]" ],
821+
commandDescription = Just $ \pname -> wrapText $
822+
"If necessary (re)configures with `--enable-benchmarks` flag and"
823+
++ " builds the benchmarks.\n"
824+
++ "\n"
825+
++ "Remember that the benchmarks' dependencies must be installed if"
826+
++ " there are additional ones; e.g. with `" ++ pname
827+
++ " v1-install --only-dependencies --enable-benchmarks`.\n"
828+
++ "\n"
829+
++ "By defining UserHooks in a custom Setup.hs, the package can"
830+
++ " define actions to be executed before and after running"
831+
++ " benchmarks.\n",
768832
commandDefaultFlags = (commandDefaultFlags parent,
769833
Cabal.defaultBuildFlags, mempty),
770834
commandOptions =
@@ -1125,7 +1189,7 @@ updateCommand = CommandUI {
11251189
relevantConfigValuesText ["remote-repo"
11261190
,"remote-repo-cache"
11271191
,"local-repo"],
1128-
commandUsage = usageFlags "update",
1192+
commandUsage = usageFlags "v1-update",
11291193
commandDefaultFlags = defaultUpdateFlags,
11301194
commandOptions = \_ -> [
11311195
optionVerbosity updateVerbosity (\v flags -> flags { updateVerbosity = v }),
@@ -1227,15 +1291,15 @@ runCommand = CommandUI {
12271291
++ "specified, but the package contains just one executable, that one "
12281292
++ "is built and executed.\n"
12291293
++ "\n"
1230-
++ "Use `" ++ pname ++ " test --show-details=streaming` to run a "
1294+
++ "Use `" ++ pname ++ " v1-test --show-details=streaming` to run a "
12311295
++ "test-suite and get its full output.\n",
12321296
commandNotes = Just $ \pname ->
12331297
"Examples:\n"
12341298
++ " " ++ pname ++ " v1-run\n"
12351299
++ " Run the only executable in the current package;\n"
12361300
++ " " ++ pname ++ " v1-run foo -- --fooflag\n"
12371301
++ " Works similar to `./foo --fooflag`.\n",
1238-
commandUsage = usageAlternatives "run"
1302+
commandUsage = usageAlternatives "v1-run"
12391303
["[FLAGS] [EXECUTABLE] [-- EXECUTABLE_FLAGS]"],
12401304
commandDefaultFlags = mempty,
12411305
commandOptions =
@@ -1613,7 +1677,7 @@ installCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFl
16131677
installCommand = CommandUI {
16141678
commandName = "install",
16151679
commandSynopsis = "Install packages.",
1616-
commandUsage = usageAlternatives "install" [ "[FLAGS]"
1680+
commandUsage = usageAlternatives "v1-install" [ "[FLAGS]"
16171681
, "[FLAGS] PACKAGES"
16181682
],
16191683
commandDescription = Just $ \_ -> wrapText $
@@ -1626,12 +1690,12 @@ installCommand = CommandUI {
16261690
++ " dependencies) (there must be exactly one .cabal file in the current"
16271691
++ " directory).\n"
16281692
++ "\n"
1629-
++ "When using a sandbox, the flags for `install` only affect the"
1693+
++ "When using a sandbox, the flags for `v1-install` only affect the"
16301694
++ " current command and have no effect on future commands. (To achieve"
1631-
++ " that, `configure` must be used.)\n"
1632-
++ " In contrast, without a sandbox, the flags to `install` are saved and"
1633-
++ " affect future commands such as `build` and `repl`. See the help for"
1634-
++ " `configure` for a list of commands being affected.\n"
1695+
++ " that, `v1-configure` must be used.)\n"
1696+
++ " In contrast, without a sandbox, the flags to `v1-install` are saved and"
1697+
++ " affect future commands such as `v1-build` and `v1-repl`. See the help for"
1698+
++ " `v1-configure` for a list of commands being affected.\n"
16351699
++ "\n"
16361700
++ "Installed executables will by default (and without a sandbox)"
16371701
++ " be put into `~/.cabal/bin/`."
@@ -1687,6 +1751,13 @@ installCommand = CommandUI {
16871751
get3 (_,_,c,_) = c; set3 c (a,b,_,d) = (a,b,c,d)
16881752
get4 (_,_,_,d) = d; set4 d (a,b,c,_) = (a,b,c,d)
16891753

1754+
haddockCommand :: CommandUI HaddockFlags
1755+
haddockCommand = Cabal.haddockCommand
1756+
{ commandName = "v1-haddock"
1757+
, commandUsage = usageAlternatives "v1-haddock" $
1758+
[ "[FLAGS]", "COMPONENTS [FLAGS]" ]
1759+
}
1760+
16901761
filterHaddockArgs :: [String] -> Version -> [String]
16911762
filterHaddockArgs args cabalLibVersion
16921763
| cabalLibVersion >= mkVersion [2,3,0] = args_latest
@@ -2427,20 +2498,20 @@ execCommand = CommandUI {
24272498
-- TODO: this is too GHC-focused for my liking..
24282499
"A directly invoked GHC will not automatically be aware of any"
24292500
++ " sandboxes: the GHC_PACKAGE_PATH environment variable controls what"
2430-
++ " GHC uses. `" ++ pname ++ " exec` can be used to modify this variable:"
2501+
++ " GHC uses. `" ++ pname ++ " v1-exec` can be used to modify this variable:"
24312502
++ " COMMAND will be executed in a modified environment and thereby uses"
24322503
++ " the sandbox package database.\n"
24332504
++ "\n"
24342505
++ "If there is no sandbox, behaves as identity (executing COMMAND).\n"
24352506
++ "\n"
24362507
++ "Note that other " ++ pname ++ " commands change the environment"
24372508
++ " variable appropriately already, so there is no need to wrap those"
2438-
++ " in `" ++ pname ++ " exec`. But with `" ++ pname ++ " exec`, the user"
2509+
++ " in `" ++ pname ++ " v1-exec`. But with `" ++ pname ++ " v1-exec`, the user"
24392510
++ " has more control and can, for example, execute custom scripts which"
24402511
++ " indirectly execute GHC.\n"
24412512
++ "\n"
2442-
++ "Note that `" ++ pname ++ " repl` is different from `" ++ pname
2443-
++ " exec -- ghci` as the latter will not forward any additional flags"
2513+
++ "Note that `" ++ pname ++ " v1-repl` is different from `" ++ pname
2514+
++ " v1-exec -- ghci` as the latter will not forward any additional flags"
24442515
++ " being defined in the local package to ghci.\n"
24452516
++ "\n"
24462517
++ "See `" ++ pname ++ " sandbox`.\n",
@@ -2454,7 +2525,7 @@ execCommand = CommandUI {
24542525
++ " Execute runghc on Foo.hs with runghc configured to use the\n"
24552526
++ " sandbox package database (if a sandbox is being used).\n",
24562527
commandUsage = \pname ->
2457-
"Usage: " ++ pname ++ " exec [FLAGS] [--] COMMAND [--] [ARGS]\n",
2528+
"Usage: " ++ pname ++ " v1-exec [FLAGS] [--] COMMAND [--] [ARGS]\n",
24582529

24592530
commandDefaultFlags = defaultExecFlags,
24602531
commandOptions = \showOrParseArgs ->

cabal-install/main/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ import Distribution.Client.Setup
4747
, UserConfigFlags(..), userConfigCommand
4848
, reportCommand
4949
, manpageCommand
50+
, haddockCommand
5051
)
5152
import Distribution.Simple.Setup
5253
( HaddockTarget(..)
5354
, DoctestFlags(..), doctestCommand
54-
, HaddockFlags(..), haddockCommand, defaultHaddockFlags
55+
, HaddockFlags(..), defaultHaddockFlags
5556
, HscolourFlags(..), hscolourCommand
5657
, ReplFlags(..)
5758
, CopyFlags(..), copyCommand

0 commit comments

Comments
 (0)