@@ -63,28 +63,40 @@ mkHUMode :: CmdLineArgs -> RawPMArgs -> Either String Mode.HUMode
63
63
mkHUMode cmdLine raw
64
64
| cmdLineHelp cmdLine = pure Mode. HelpMode
65
65
| cmdLineVersion cmdLine = pure Mode. VersionMode
66
- | otherwise = fmap (Mode. RunMode runModifier)
67
- $ go $ maybe
68
- (cmdLinePkgManager cmdLine)
69
- CustomPM
70
- (cmdLineCustomPM cmdLine)
66
+ | otherwise = do
67
+ let pkgMgr = maybe
68
+ (cmdLinePkgManager cmdLine)
69
+ CustomPM
70
+ (cmdLineCustomPM cmdLine)
71
+ mPkgMgr <- go pkgMgr
72
+ pure $ Mode. RunMode runModifier mPkgMgr
71
73
where
72
74
go :: PkgManager -> Either String Mode. PkgManager
73
75
go pkgMgr = case (pkgMgr, cmdLineMode cmdLine, cmdLineTarget cmdLine) of
74
- (Portage , ReinstallAtomsMode , WorldTarget ) -> pure
76
+ (Portage , ReinstallAtomsMode , Right WorldTarget ) -> pure
75
77
$ Mode. Portage $ Right $ Mode. ReinstallAtomsMode
76
78
$ Right $ Mode. WorldTarget
77
- (Portage , _, WorldTarget ) -> Left
79
+ (Portage , ReinstallAtomsMode , Left targs) -> pure
80
+ $ Mode. Portage $ Right $ Mode. ReinstallAtomsMode
81
+ $ Right $ Mode. CustomTargets targs
82
+ (Portage , _, Right WorldTarget ) -> Left
78
83
" \" world\" target is only valid with reinstall-atoms mode"
79
- (Portage , ReinstallAtomsMode , targ) -> pure
84
+ (Portage , _, Left _) -> Left
85
+ " custom targets are only valid with reinstall-atoms mode"
86
+ (Portage , ReinstallAtomsMode , Right targ) -> pure
80
87
$ Mode. Portage $ Right $ Mode. ReinstallAtomsMode
81
88
$ Left $ convTarget targ
82
- (_, ReinstallAtomsMode , WorldTarget ) -> Left
89
+ (_, ReinstallAtomsMode , Right WorldTarget ) -> Left
83
90
" \" world\" target is only valid with portage package manager"
84
- (_, ReinstallAtomsMode , _) -> Left $ unwords
85
- [" \" world\" target is only valid with reinstall-atoms mode and portage"
91
+ (_, _, Right WorldTarget ) -> Left $ unwords
92
+ [ " \" world\" target is only valid with reinstall-atoms mode and portage"
93
+ , " package manager" ]
94
+ (_, _, Left _) -> Left $ unwords
95
+ [ " custom targets are only valid with reinstall-atoms mode and portage"
86
96
, " package manager" ]
87
- (_, mode, targ) -> pure $ convPkgMgr pkgMgr mode targ
97
+ (_, ReinstallAtomsMode , _) -> Left
98
+ " reinstall-atoms mode is only valid with portage package manager"
99
+ (_, mode, Right targ) -> pure $ convPkgMgr pkgMgr mode targ
88
100
89
101
convPkgMgr :: PkgManager -> RunMode -> BuildTarget -> Mode. PkgManager
90
102
convPkgMgr Portage mode targ = Mode. Portage $ Left $ convMode mode targ
@@ -138,7 +150,7 @@ options =
138
150
, Option [' C' ] [" custom-pm" ]
139
151
(ReqArg (\ s c -> pure $ c { cmdLineCustomPM = Just s }) " command" )
140
152
$ " Use custom command as package manager;\n "
141
- ++ " ignores the --pretend and --no-deep flags."
153
+ ++ " ignores the --pretend and --no-deep flags."
142
154
, Option [' p' ] [" pretend" ]
143
155
(naUpdate $ \ c -> c { cmdLinePretend = True } )
144
156
" Only pretend to build packages."
@@ -152,27 +164,37 @@ options =
152
164
(ReqArg (fromCmdline (\ a c -> c { cmdLineAction = a })) " action" )
153
165
(argHelp (Proxy @ WithCmd ))
154
166
, Option [] [" target" ]
155
- (ReqArg (fromCmdline (\ a c -> c { cmdLineTarget = a } )) " target" )
167
+ (ReqArg (fromCmdline (\ a -> updateTarget ( Right a) )) " target" )
156
168
(argHelp (Proxy @ BuildTarget ))
157
169
, Option [' c' ] [" dep-check" ]
158
- (naUpdate $ \ c -> c { cmdLineTarget = OnlyInvalid } )
170
+ (naUpdate $ updateTarget ( Right OnlyInvalid ) )
159
171
$ " alias for --target=" ++ argString OnlyInvalid
160
172
-- deprecated alias for 'dep-check'
161
173
, Option [' u' ] [" upgrade" ]
162
- (naUpdate $ \ c -> c { cmdLineTarget = OnlyInvalid } )
174
+ (naUpdate $ updateTarget ( Right OnlyInvalid ) )
163
175
$ " alias for --target=" ++ argString OnlyInvalid
164
176
, Option [' a' ] [" all" ]
165
- (naUpdate $ \ c -> c { cmdLineTarget = AllInstalled } )
177
+ (naUpdate $ updateTarget ( Right AllInstalled ) )
166
178
$ " alias for --target=" ++ argString AllInstalled
167
179
, Option [' W' ] [" world" ]
168
- (naUpdate $ \ r -> r
180
+ (naUpdate $ \ c -> updateTarget ( Right WorldTarget ) c
169
181
{ cmdLinePkgManager = Portage
170
- , cmdLineTarget = WorldTarget
171
182
, cmdLineMode = ReinstallAtomsMode
172
183
}
173
184
) $ " alias for --package-manager=portage"
174
185
++ " \\\n --target=" ++ argString WorldTarget
175
186
++ " \\\n --mode=" ++ argString ReinstallAtomsMode
187
+ , Option [' T' ] [" custom-target" ]
188
+ (ReqArg
189
+ (\ s c -> pure $ updateTarget (Left s) c
190
+ { cmdLinePkgManager = Portage
191
+ , cmdLineMode = ReinstallAtomsMode
192
+ }
193
+ )
194
+ " target" )
195
+ $ " Use a custom target. May be given multiple times.\n "
196
+ ++ " Enables portage PM and reinstall-targets mode.\n "
197
+ ++ " Will override any non-custom targets."
176
198
, Option [] [" mode" ]
177
199
(ReqArg (fromCmdline (\ a c -> c { cmdLineMode = a })) " mode" )
178
200
(argHelp (Proxy @ RunMode ))
@@ -207,9 +229,25 @@ options =
207
229
208
230
pmList = unlines . map (" * " ++ ) $ definedPMs
209
231
defPM = " The last valid value of PM specified is chosen.\n \
210
- \The default package manager is: " ++ defaultPMName ++ " ,\n \
211
- \which can be overriden with the \" PACKAGE_MANAGER\"\n \
212
- \environment variable."
232
+ \ The default package manager is: " ++ defaultPMName ++ " ,\n \
233
+ \ which can be overriden with the \" PACKAGE_MANAGER\"\n \
234
+ \ environment variable."
235
+
236
+ -- Custom targets always override BuildTargets
237
+ -- New custom targets are appended to old custom targets
238
+ -- New BuildTargets override old BuildTargets
239
+ updateTarget :: Either String BuildTarget -> CmdLineArgs -> CmdLineArgs
240
+ updateTarget new old =
241
+ let newT = case (new, cmdLineTarget old) of
242
+ -- Override old BuildTargets with new BuildTargets
243
+ (Right t, Right _) -> Right t
244
+ -- Append new custom target
245
+ (Left s, Left ss) -> Left $ ss ++ [s]
246
+ -- Drop old BuildTargets for new custom target
247
+ (Left s, Right _) -> Left [s]
248
+ -- Drop new BuildTargets in favor of old custom targets
249
+ (Right _, Left ss) -> Left ss
250
+ in old { cmdLineTarget = newT }
213
251
214
252
215
253
0 commit comments