|
| 1 | +{-# LANGUAGE OverloadedStrings #-} |
| 2 | +{-# LANGUAGE FlexibleInstances #-} |
| 3 | +{-# LANGUAGE RecordWildCards #-} |
| 4 | +{-# LANGUAGE ViewPatterns #-} |
| 5 | +module Distribution.Client.CmdLegacy (legacyCmd) where |
| 6 | + |
| 7 | +import Prelude () |
| 8 | +import Distribution.Client.Compat.Prelude |
| 9 | + |
| 10 | +import qualified Distribution.Client.Setup as Client |
| 11 | +import qualified Distribution.Simple.Setup as Setup |
| 12 | +import Distribution.Simple.Command |
| 13 | +import Distribution.Simple.Utils |
| 14 | + ( warn ) |
| 15 | +import Distribution.Verbosity |
| 16 | + ( Verbosity, normal ) |
| 17 | + |
| 18 | +import qualified Data.Text as T |
| 19 | + |
| 20 | +-- Duplicated code (it's identical to Main.regularCmd), but makes things cleaner |
| 21 | +-- and lets me keep how this happens a dirty little secret. |
| 22 | +makeCmd :: CommandUI flags -> (flags -> [String] -> action) -> CommandSpec action |
| 23 | +makeCmd ui action = CommandSpec ui ((flip commandAddAction) action) NormalCommand |
| 24 | + |
| 25 | +deprecationNote :: String -> String |
| 26 | +deprecationNote cmd = |
| 27 | + "The " ++ cmd ++ " command is a part of the legacy v1 style of cabal usage.\n\n" ++ |
| 28 | + |
| 29 | + "Please switch to using either the new project style or the legacy v1-" ++ cmd ++ "\n" ++ |
| 30 | + "alias as new-style projects will become the default in the next version of\n" ++ |
| 31 | + "cabal-install. Please file a bug if you cannot replicate a working v1- use\n" ++ |
| 32 | + "case with the new-style commands.\n" |
| 33 | + |
| 34 | +legacyNote :: String -> String |
| 35 | +legacyNote cmd = |
| 36 | + "The v1-" ++ cmd ++ " command is a part of the legacy v1 style of cabal usage.\n\n" ++ |
| 37 | + |
| 38 | + "It is a legacy feature and will be removed in a future release of cabal-install.\n" ++ |
| 39 | + "Please file a bug if you cannot replicate a working v1- use case with the new-style\n" ++ |
| 40 | + "commands.\n" |
| 41 | + |
| 42 | +-- |
| 43 | + |
| 44 | +class HasVerbosity a where |
| 45 | + verbosity :: a -> Verbosity |
| 46 | + |
| 47 | +instance HasVerbosity (Setup.Flag Verbosity) where |
| 48 | + verbosity = Setup.fromFlagOrDefault normal |
| 49 | + |
| 50 | +instance (HasVerbosity a) => HasVerbosity (a, b) where |
| 51 | + verbosity (a, _) = verbosity a |
| 52 | + |
| 53 | +instance (HasVerbosity b) => HasVerbosity (a, b, c) where |
| 54 | + verbosity (_ , b, _) = verbosity b |
| 55 | + |
| 56 | +instance (HasVerbosity a) => HasVerbosity (a, b, c, d) where |
| 57 | + verbosity (a, _, _, _) = verbosity a |
| 58 | + |
| 59 | +instance HasVerbosity Setup.BuildFlags where |
| 60 | + verbosity = verbosity . Setup.buildVerbosity |
| 61 | + |
| 62 | +instance HasVerbosity Setup.ConfigFlags where |
| 63 | + verbosity = verbosity . Setup.configVerbosity |
| 64 | + |
| 65 | +instance HasVerbosity Setup.ReplFlags where |
| 66 | + verbosity = verbosity . Setup.replVerbosity |
| 67 | + |
| 68 | +instance HasVerbosity Client.FreezeFlags where |
| 69 | + verbosity = verbosity . Client.freezeVerbosity |
| 70 | + |
| 71 | +instance HasVerbosity Setup.HaddockFlags where |
| 72 | + verbosity = verbosity . Setup.haddockVerbosity |
| 73 | + |
| 74 | +instance HasVerbosity Client.ExecFlags where |
| 75 | + verbosity = verbosity . Client.execVerbosity |
| 76 | + |
| 77 | +instance HasVerbosity Client.UpdateFlags where |
| 78 | + verbosity = verbosity . Client.updateVerbosity |
| 79 | + |
| 80 | +instance HasVerbosity Setup.CleanFlags where |
| 81 | + verbosity = verbosity . Setup.cleanVerbosity |
| 82 | + |
| 83 | +-- |
| 84 | + |
| 85 | +legacyCmd :: (HasVerbosity flags) => CommandUI flags -> (flags -> [String] -> globals -> IO action) -> [CommandSpec (globals -> IO action)] |
| 86 | +legacyCmd origUi@CommandUI{..} action = [makeCmd legUi action, makeCmd depUi depAction] |
| 87 | + where |
| 88 | + legacyMsg = T.unpack . T.replace "v1-" "" . T.pack |
| 89 | + |
| 90 | + depNote = deprecationNote commandName |
| 91 | + legNote = legacyNote commandName |
| 92 | + |
| 93 | + depAction flags extra globals = warn (verbosity flags) (depNote ++ "\n") >> action flags extra globals |
| 94 | + |
| 95 | + legUi = origUi |
| 96 | + { commandName = "v1-" ++ commandName |
| 97 | + , commandNotes = Just $ \pname -> case commandNotes of |
| 98 | + Just notes -> notes pname ++ "\n" ++ legNote |
| 99 | + Nothing -> legNote |
| 100 | + } |
| 101 | + |
| 102 | + depUi = origUi |
| 103 | + { commandName = legacyMsg commandName |
| 104 | + , commandUsage = legacyMsg . commandUsage |
| 105 | + , commandDescription = (legacyMsg .) <$> commandDescription |
| 106 | + , commandNotes = Just $ \pname -> case commandNotes of |
| 107 | + Just notes -> legacyMsg (notes pname) ++ "\n" ++ depNote |
| 108 | + Nothing -> depNote |
| 109 | + } |
0 commit comments