Skip to content

Commit 31587d1

Browse files
authored
Merge pull request #6728 from commercialhaskell/upload
Prettier output for loadAuth info
2 parents 652ec58 + be2c3aa commit 31587d1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/Stack/Upload.hs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE DuplicateRecordFields #-}
3+
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE NoFieldSelectors #-}
45
{-# LANGUAGE OverloadedRecordDot #-}
56
{-# LANGUAGE OverloadedStrings #-}
@@ -266,6 +267,7 @@ uploadCmd uo = do
266267
(as, bs) <- partitionM f xs
267268
pure $ if r then (x:as, bs) else (as, x:bs)
268269

270+
-- | Type representing Hackage API authentification tokens.
269271
newtype HackageKey = HackageKey Text
270272
deriving (Eq, Show)
271273

@@ -279,9 +281,12 @@ data HackageCreds = HackageCreds
279281
}
280282
deriving (Eq, Show)
281283

284+
-- | Type representing Hackage authentifications
282285
data HackageAuth
283286
= HAKey HackageKey
287+
-- ^ With a Hackage API authentification token registered by a user.
284288
| HACreds HackageCreds
289+
-- ^ With a Hackage user's credentials.
285290
deriving (Eq, Show)
286291

287292
instance ToJSON HackageCreds where
@@ -299,19 +304,23 @@ withEnvVariable :: Text -> IO Text -> IO Text
299304
withEnvVariable varName fromPrompt =
300305
lookupEnv (T.unpack varName) >>= maybe fromPrompt (pure . T.pack)
301306

307+
-- | Optionally, load Hackage API authentification token from the @HACKAGE_KEY@
308+
-- environment variable, if it exists.
302309
maybeGetHackageKey :: RIO m (Maybe HackageKey)
303310
maybeGetHackageKey =
304311
liftIO $ fmap (HackageKey . T.pack) <$> lookupEnv "HACKAGE_KEY"
305312

313+
-- | Load Hackage authentification from the environment, if applicable, or from
314+
-- the given configuration.
306315
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
315324

316325
-- | Load Hackage credentials, either from a save file or the command
317326
-- line.
@@ -564,6 +573,7 @@ upload baseUrl auth contentForm mPkgIdName fp uploadVariant =
564573
baseUrl auth contentForm mPkgIdName (FP.takeFileName fp) uploadVariant
565574
=<< liftIO (L.readFile fp)
566575

576+
-- | Upload a revised Cabal file for the given package.
567577
uploadRevision ::
568578
(HasLogFunc m, HasTerm m)
569579
=> String -- ^ Hackage base URL

0 commit comments

Comments
 (0)