@@ -77,9 +77,9 @@ playgroundProfiles = profilesNoEraPlayground
77
77
--------------------------------------------------------------------------------
78
78
79
79
data Cli =
80
- Names
81
- | NamesNoEra
80
+ NamesNoEra
82
81
| NamesCloudNoEra
82
+ | Names
83
83
| All
84
84
| ByName PrettyPrint String
85
85
| LibMK
@@ -94,11 +94,14 @@ data PrettyPrint =
94
94
--------------------------------------------------------------------------------
95
95
96
96
-- | Construct Map with profile name as key, without eras (in name and object).
97
- toMap :: HasCallStack => Aeson. Object -> [Types. Profile ] -> Map. Map String Types. Profile
98
- toMap obj ps = Map. fromList $ map
97
+ toMap :: HasCallStack => Maybe Aeson. Object -> [Types. Profile ] -> Map. Map String Types. Profile
98
+ toMap maybeObj ps = Map. fromList $ map
99
99
(\ p ->
100
100
( Types. name p
101
- , Profile. realize obj p
101
+ , Profile. realize $
102
+ case maybeObj of
103
+ Nothing -> p
104
+ (Just obj) -> (p {Types. overlay = obj})
102
105
)
103
106
)
104
107
ps
@@ -132,20 +135,22 @@ main :: IO ()
132
135
main = do
133
136
cli <- getOpts
134
137
case cli of
135
- -- Print all profile names (does not apply overlays).
136
- Names -> BSL8. putStrLn $ Aeson. encode $ Map. keys $ addEras $ toMap mempty allProfiles
137
138
-- Print all profile names without the era suffix (does not apply overlays).
138
139
NamesNoEra -> BSL8. putStrLn $ Aeson. encode $ map Types. name allProfiles
139
- -- Print all cloud profile (-nomadperf) names.
140
+ -- Print all cloud profile (-nomadperf) names (does not apply overlays) .
140
141
NamesCloudNoEra -> BSL8. putStrLn $ Aeson. encode $ map Types. name cloudProfiles
142
+ -- Print all profile names (applies overlays!!!!!).
143
+ Names -> do
144
+ maybeObj <- lookupOverlay -- Ignored by `NamesNoEra` and `NamesCloudNoEra`.
145
+ BSL8. putStrLn $ Aeson. encode $ Map. keys $ addEras $ toMap maybeObj allProfiles
141
146
-- Print a map with all profiles, with an optional overlay.
142
147
All -> do
143
- obj <- lookupOverlay
144
- BSL8. putStrLn $ Aeson. encode $ addEras $ toMap obj allProfiles
148
+ maybeObj <- lookupOverlay -- Ignored by `NamesNoEra` and `NamesCloudNoEra`.
149
+ BSL8. putStrLn $ Aeson. encode $ addEras $ toMap maybeObj allProfiles
145
150
-- Print a single profiles, with an optional overlay.
146
151
(ByName prettyPrint profileName) -> do
147
- obj <- lookupOverlay
148
- let profiles = addEras $ toMap obj allProfiles
152
+ maybeObj <- lookupOverlay -- Ignored by `NamesNoEra` and `NamesCloudNoEra`.
153
+ let profiles = addEras $ toMap maybeObj allProfiles
149
154
case Map. lookup profileName profiles of
150
155
Nothing -> error $ " No profile named \" " ++ profileName ++ " \" "
151
156
(Just profile) ->
@@ -181,13 +186,13 @@ main = do
181
186
(Left errorMsg) -> fail errorMsg
182
187
(Right profile) -> print (profile :: Types. Profile )
183
188
184
- lookupOverlay :: IO Aeson. Object
189
+ lookupOverlay :: IO ( Maybe Aeson. Object)
185
190
lookupOverlay = do
186
191
maybeOverlay <- lookupEnv " WB_PROFILE_OVERLAY"
187
- case maybeOverlay of
188
- Nothing -> mempty
192
+ return $ case maybeOverlay of
193
+ Nothing -> Nothing
189
194
(Just str) -> case Aeson. decode (BSL8. pack str) of
190
- (Just (Aeson. Object keyMap)) -> return keyMap
195
+ (Just (Aeson. Object keyMap)) -> Just keyMap
191
196
_ -> error " "
192
197
193
198
getOpts :: IO Cli
@@ -200,12 +205,6 @@ getOpts = OA.execParser $
200
205
201
206
cliParser :: OA. Parser Cli
202
207
cliParser = OA. hsubparser $
203
- OA. command " names"
204
- (OA. info
205
- (pure Names )
206
- (OA. fullDesc <> OA. header " names" <> OA. progDesc " All profiles names" )
207
- )
208
- <>
209
208
OA. command " names-noera"
210
209
(OA. info
211
210
(pure NamesNoEra )
@@ -217,6 +216,12 @@ cliParser = OA.hsubparser $
217
216
(pure NamesCloudNoEra )
218
217
(OA. fullDesc <> OA. header " names-cloud-noera" <> OA. progDesc " All cloud profiles names (no era suffix)" )
219
218
)
219
+ <>
220
+ OA. command " names"
221
+ (OA. info
222
+ (pure Names )
223
+ (OA. fullDesc <> OA. header " names" <> OA. progDesc " All profiles names" )
224
+ )
220
225
<>
221
226
OA. command " all"
222
227
(OA. info
0 commit comments