1
1
{-# LANGUAGE NoImplicitPrelude #-}
2
2
{-# LANGUAGE DuplicateRecordFields #-}
3
+ {-# LANGUAGE LambdaCase #-}
3
4
{-# LANGUAGE NoFieldSelectors #-}
4
5
{-# LANGUAGE OverloadedRecordDot #-}
5
6
{-# LANGUAGE OverloadedStrings #-}
@@ -266,6 +267,7 @@ uploadCmd uo = do
266
267
(as, bs) <- partitionM f xs
267
268
pure $ if r then (x: as, bs) else (as, x: bs)
268
269
270
+ -- | Type representing Hackage API authentification tokens.
269
271
newtype HackageKey = HackageKey Text
270
272
deriving (Eq , Show )
271
273
@@ -279,9 +281,12 @@ data HackageCreds = HackageCreds
279
281
}
280
282
deriving (Eq , Show )
281
283
284
+ -- | Type representing Hackage authentifications
282
285
data HackageAuth
283
286
= HAKey HackageKey
287
+ -- ^ With a Hackage API authentification token registered by a user.
284
288
| HACreds HackageCreds
289
+ -- ^ With a Hackage user's credentials.
285
290
deriving (Eq , Show )
286
291
287
292
instance ToJSON HackageCreds where
@@ -299,19 +304,23 @@ withEnvVariable :: Text -> IO Text -> IO Text
299
304
withEnvVariable varName fromPrompt =
300
305
lookupEnv (T. unpack varName) >>= maybe fromPrompt (pure . T. pack)
301
306
307
+ -- | Optionally, load Hackage API authentification token from the @HACKAGE_KEY@
308
+ -- environment variable, if it exists.
302
309
maybeGetHackageKey :: RIO m (Maybe HackageKey )
303
310
maybeGetHackageKey =
304
311
liftIO $ fmap (HackageKey . T. pack) <$> lookupEnv " HACKAGE_KEY"
305
312
313
+ -- | Load Hackage authentification from the environment, if applicable, or from
314
+ -- the given configuration.
306
315
loadAuth :: (HasLogFunc m , HasTerm m ) => Config -> RIO m HackageAuth
307
- loadAuth config = do
308
- maybeHackageKey <- maybeGetHackageKey
309
- case maybeHackageKey of
310
- Just key -> do
311
- prettyInfoS
312
- " HACKAGE_KEY environment variable found, using that for credentials. "
313
- pure $ HAKey key
314
- Nothing -> HACreds <$> loadUserAndPassword config
316
+ loadAuth config = maybeGetHackageKey >>= \ case
317
+ Just key -> do
318
+ prettyInfoL
319
+ [ style Shell " HACKAGE_KEY "
320
+ , flow " environment variable found, using that for credentials. "
321
+ ]
322
+ pure $ HAKey key
323
+ Nothing -> HACreds <$> loadUserAndPassword config
315
324
316
325
-- | Load Hackage credentials, either from a save file or the command
317
326
-- line.
@@ -564,6 +573,7 @@ upload baseUrl auth contentForm mPkgIdName fp uploadVariant =
564
573
baseUrl auth contentForm mPkgIdName (FP. takeFileName fp) uploadVariant
565
574
=<< liftIO (L. readFile fp)
566
575
576
+ -- | Upload a revised Cabal file for the given package.
567
577
uploadRevision ::
568
578
(HasLogFunc m , HasTerm m )
569
579
=> String -- ^ Hackage base URL
0 commit comments