@@ -8,24 +8,23 @@ module Distribution.Client.CmdInstall.ClientInstallFlags
8
8
) where
9
9
10
10
import Distribution.Client.Compat.Prelude
11
+ import Prelude ()
11
12
12
13
import Distribution.ReadE
13
- ( ReadE ( .. ), succeedReadE )
14
+ ( succeedReadE , parsecToReadE )
14
15
import Distribution.Simple.Command
15
16
( ShowOrParseArgs (.. ), OptionField (.. ), option , reqArg )
16
17
import Distribution.Simple.Setup
17
18
( Flag (.. ), trueArg , flagToList , toFlag )
19
+ import Distribution.Parsec (Parsec (.. ), CabalParsing )
20
+ import Distribution.Pretty (prettyShow )
18
21
19
- import Distribution.Client.InstallSymlink
22
+ import Distribution.Client.Types.InstallMethod
23
+ ( InstallMethod (.. ) )
24
+ import Distribution.Client.Types.OverwritePolicy
20
25
( OverwritePolicy (.. ) )
21
26
22
-
23
- data InstallMethod = InstallMethodCopy
24
- | InstallMethodSymlink
25
- deriving (Eq , Show , Generic , Bounded , Enum )
26
-
27
- instance Binary InstallMethod
28
- instance Structured InstallMethod
27
+ import qualified Distribution.Compat.CharParsing as P
29
28
30
29
data ClientInstallFlags = ClientInstallFlags
31
30
{ cinstInstallLibs :: Flag Bool
@@ -67,42 +66,26 @@ clientInstallOptions _ =
67
66
, option [] [" overwrite-policy" ]
68
67
" How to handle already existing symlinks."
69
68
cinstOverwritePolicy (\ v flags -> flags { cinstOverwritePolicy = v })
70
- $ reqArg
71
- " always|never"
72
- readOverwritePolicyFlag
73
- showOverwritePolicyFlag
69
+ $ reqArg " always|never"
70
+ (parsecToReadE (\ err -> " Error parsing overwrite-policy: " ++ err) (toFlag `fmap` parsec))
71
+ (map prettyShow . flagToList)
74
72
, option [] [" install-method" ]
75
73
" How to install the executables."
76
74
cinstInstallMethod (\ v flags -> flags { cinstInstallMethod = v })
77
75
$ reqArg
78
76
" default|copy|symlink"
79
- readInstallMethodFlag
80
- showInstallMethodFlag
77
+ (parsecToReadE ( \ err -> " Error parsing install-method: " ++ err) (toFlag `fmap` parsecInstallMethod))
78
+ ( map prettyShow . flagToList)
81
79
, option [] [" installdir" ]
82
80
" Where to install (by symlinking or copying) the executables in."
83
81
cinstInstalldir (\ v flags -> flags { cinstInstalldir = v })
84
82
$ reqArg " DIR" (succeedReadE Flag ) flagToList
85
83
]
86
84
87
- readOverwritePolicyFlag :: ReadE (Flag OverwritePolicy )
88
- readOverwritePolicyFlag = ReadE $ \ case
89
- " always" -> Right $ Flag AlwaysOverwrite
90
- " never" -> Right $ Flag NeverOverwrite
91
- policy -> Left $ " '" <> policy <> " ' isn't a valid overwrite policy"
92
-
93
- showOverwritePolicyFlag :: Flag OverwritePolicy -> [String ]
94
- showOverwritePolicyFlag (Flag AlwaysOverwrite ) = [" always" ]
95
- showOverwritePolicyFlag (Flag NeverOverwrite ) = [" never" ]
96
- showOverwritePolicyFlag NoFlag = []
97
-
98
- readInstallMethodFlag :: ReadE (Flag InstallMethod )
99
- readInstallMethodFlag = ReadE $ \ case
100
- " default" -> Right $ NoFlag
101
- " copy" -> Right $ Flag InstallMethodCopy
102
- " symlink" -> Right $ Flag InstallMethodSymlink
103
- method -> Left $ " '" <> method <> " ' isn't a valid install-method"
104
-
105
- showInstallMethodFlag :: Flag InstallMethod -> [String ]
106
- showInstallMethodFlag (Flag InstallMethodCopy ) = [" copy" ]
107
- showInstallMethodFlag (Flag InstallMethodSymlink ) = [" symlink" ]
108
- showInstallMethodFlag NoFlag = []
85
+ parsecInstallMethod :: CabalParsing m => m InstallMethod
86
+ parsecInstallMethod = do
87
+ name <- P. munch1 isAlpha
88
+ case name of
89
+ " copy" -> pure InstallMethodCopy
90
+ " symlink" -> pure InstallMethodSymlink
91
+ _ -> P. unexpected $ " InstallMethod: " ++ name
0 commit comments