Skip to content
This repository was archived by the owner on Dec 7, 2023. It is now read-only.

Commit 2c1c003

Browse files
committed
minor stuff
* relude-1.0 * progress bar is now threadsafe * better auth error messages
1 parent 56b033d commit 2c1c003

File tree

10 files changed

+137
-59
lines changed

10 files changed

+137
-59
lines changed

.hlint.yaml

Lines changed: 107 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,22 @@
218218
- warn:
219219
lhs: "f <$> nonEmpty x"
220220
rhs: viaNonEmpty f x
221+
- warn:
222+
lhs: partitionEithers . map f
223+
rhs: partitionWith f
224+
- warn:
225+
lhs: partitionEithers $ map f x
226+
rhs: partitionWith f x
221227
- warn:
222228
lhs: "f >>= guard"
223229
rhs: guardM f
224230
- warn:
225-
lhs: "guard =<< f"
231+
lhs: guard =<< f
226232
rhs: guardM f
233+
- warn:
234+
lhs: forever
235+
note: "'forever' is loosely typed and may hide errors"
236+
rhs: infinitely
227237
- warn:
228238
lhs: "whenM (not <$> x)"
229239
rhs: unlessM x
@@ -309,7 +319,7 @@
309319
lhs: "maybe (return ()) f =<< m"
310320
rhs: whenJustM m f
311321
- warn:
312-
lhs: "maybe pass f =<< m"
322+
lhs: maybe pass f =<< m
313323
rhs: whenJustM m f
314324
- warn:
315325
lhs: "m >>= maybe (pure ()) f"
@@ -1118,11 +1128,6 @@
11181128
name: "Use 'Natural' from Relude"
11191129
note: "'Natural' is already exported from Relude"
11201130
rhs: Natural
1121-
- warn:
1122-
lhs: System.IO.Handle
1123-
name: "Use 'Handle' from Relude"
1124-
note: "'Handle' is already exported from Relude"
1125-
rhs: Handle
11261131
- warn:
11271132
lhs: System.IO.IOMode
11281133
name: "Use 'IOMode' from Relude"
@@ -1148,26 +1153,6 @@
11481153
name: "Use 'ReadWriteMode' from Relude"
11491154
note: "'ReadWriteMode' is already exported from Relude"
11501155
rhs: ReadWriteMode
1151-
- warn:
1152-
lhs: System.IO.stderr
1153-
name: "Use 'stderr' from Relude"
1154-
note: "'stderr' is already exported from Relude"
1155-
rhs: stderr
1156-
- warn:
1157-
lhs: System.IO.stdin
1158-
name: "Use 'stdin' from Relude"
1159-
note: "'stdin' is already exported from Relude"
1160-
rhs: stdin
1161-
- warn:
1162-
lhs: System.IO.stdout
1163-
name: "Use 'stdout' from Relude"
1164-
note: "'stdout' is already exported from Relude"
1165-
rhs: stdout
1166-
- warn:
1167-
lhs: System.IO.withFile
1168-
name: "Use 'withFile' from Relude"
1169-
note: "'withFile' is already exported from Relude"
1170-
rhs: withFile
11711156
- warn:
11721157
lhs: Data.Ord.Down
11731158
name: "Use 'Down' from Relude"
@@ -1802,7 +1787,7 @@
18021787
lhs: Data.Function.on
18031788
name: "Use 'on' from Relude"
18041789
note: "'on' is already exported from Relude"
1805-
rhs: "on"
1790+
rhs: 'on'
18061791
- warn:
18071792
lhs: Data.Bifunctor.Bifunctor
18081793
name: "Use 'Bifunctor' from Relude"
@@ -2095,6 +2080,66 @@
20952080
name: "Use 'getLine' from Relude"
20962081
note: "'getLine' is already exported from Relude"
20972082
rhs: getLine
2083+
- warn:
2084+
lhs: System.IO.hFlush
2085+
name: "Use 'hFlush' from Relude"
2086+
note: "'hFlush' is already exported from Relude"
2087+
rhs: hFlush
2088+
- warn:
2089+
lhs: System.IO.hIsEOF
2090+
name: "Use 'hIsEOF' from Relude"
2091+
note: "'hIsEOF' is already exported from Relude"
2092+
rhs: hIsEOF
2093+
- warn:
2094+
lhs: System.IO.hSetBuffering
2095+
name: "Use 'hSetBuffering' from Relude"
2096+
note: "'hSetBuffering' is already exported from Relude"
2097+
rhs: hSetBuffering
2098+
- warn:
2099+
lhs: System.IO.hGetBuffering
2100+
name: "Use 'hGetBuffering' from Relude"
2101+
note: "'hGetBuffering' is already exported from Relude"
2102+
rhs: hGetBuffering
2103+
- warn:
2104+
lhs: System.IO.Handle
2105+
name: "Use 'Handle' from Relude"
2106+
note: "'Handle' is already exported from Relude"
2107+
rhs: Handle
2108+
- warn:
2109+
lhs: System.IO.stdin
2110+
name: "Use 'stdin' from Relude"
2111+
note: "'stdin' is already exported from Relude"
2112+
rhs: stdin
2113+
- warn:
2114+
lhs: System.IO.stdout
2115+
name: "Use 'stdout' from Relude"
2116+
note: "'stdout' is already exported from Relude"
2117+
rhs: stdout
2118+
- warn:
2119+
lhs: System.IO.stderr
2120+
name: "Use 'stderr' from Relude"
2121+
note: "'stderr' is already exported from Relude"
2122+
rhs: stderr
2123+
- warn:
2124+
lhs: System.IO.withFile
2125+
name: "Use 'withFile' from Relude"
2126+
note: "'withFile' is already exported from Relude"
2127+
rhs: withFile
2128+
- warn:
2129+
lhs: System.IO.BufferMode
2130+
name: "Use 'BufferMode' from Relude"
2131+
note: "'BufferMode' is already exported from Relude"
2132+
rhs: BufferMode
2133+
- warn:
2134+
lhs: System.Environment.getArgs
2135+
name: "Use 'getArgs' from Relude"
2136+
note: "'getArgs' is already exported from Relude"
2137+
rhs: getArgs
2138+
- warn:
2139+
lhs: System.Environment.lookupEnv
2140+
name: "Use 'lookupEnv' from Relude"
2141+
note: "'lookupEnv' is already exported from Relude"
2142+
rhs: lookupEnv
20982143
- warn:
20992144
lhs: Data.List.genericDrop
21002145
name: "Use 'genericDrop' from Relude"
@@ -3095,6 +3140,36 @@
30953140
name: "'liftIO' is not needed"
30963141
note: "If you import 'putLBSLn' from Relude, it's already lifted"
30973142
rhs: putLBSLn
3143+
- warn:
3144+
lhs: "(liftIO (hFlush x))"
3145+
name: "'liftIO' is not needed"
3146+
note: "If you import 'hFlush' from Relude, it's already lifted"
3147+
rhs: hFlush
3148+
- warn:
3149+
lhs: "(liftIO (hIsEOF x))"
3150+
name: "'liftIO' is not needed"
3151+
note: "If you import 'hIsEOF' from Relude, it's already lifted"
3152+
rhs: hIsEOF
3153+
- warn:
3154+
lhs: "(liftIO (hSetBuffering x y))"
3155+
name: "'liftIO' is not needed"
3156+
note: "If you import 'hSetBuffering' from Relude, it's already lifted"
3157+
rhs: hSetBuffering
3158+
- warn:
3159+
lhs: "(liftIO (hGetBuffering x))"
3160+
name: "'liftIO' is not needed"
3161+
note: "If you import 'hGetBuffering' from Relude, it's already lifted"
3162+
rhs: hGetBuffering
3163+
- warn:
3164+
lhs: "(liftIO (getArgs ))"
3165+
name: "'liftIO' is not needed"
3166+
note: "If you import 'getArgs' from Relude, it's already lifted"
3167+
rhs: getArgs
3168+
- warn:
3169+
lhs: "(liftIO (lookupEnv x))"
3170+
name: "'liftIO' is not needed"
3171+
note: "If you import 'lookupEnv' from Relude, it's already lifted"
3172+
rhs: lookupEnv
30983173
- hint:
30993174
lhs: "fmap (bimap f g)"
31003175
note: "Use `bimapF` from `Relude.Extra.Bifunctor`"
@@ -3135,6 +3210,10 @@
31353210
lhs: toEnum
31363211
note: "`toEnum` from `Prelude` is a pure function but it may throw exception. Consider using `safeToEnum` from `Relude.Extra.Enum` instead."
31373212
rhs: safeToEnum
3213+
- hint:
3214+
lhs: sum xs / length xs
3215+
note: "Use `average` from `Relude.Extra.Foldable`"
3216+
rhs: average xs
31383217
- hint:
31393218
lhs: "\\a -> (a, a)"
31403219
note: "Use `dup` from `Relude.Extra.Tuple`"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Some Minecraft stuff as a CLI:
1313
- Manage CurseForge mods
1414
- install
1515
- update
16+
- deduplicate
1617
- Install CurseForge modpacks
1718

1819
## ToC

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
packages: .
22

33
with-compiler: ghc-8.10.4
4-
index-state: 2021-02-14T00:00:00Z
4+
index-state: 2021-03-22T00:00:00Z

hellsmack.cabal

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ flag use-openssl
2121
manual: True
2222

2323
common commons
24-
default-extensions: AllowAmbiguousTypes ApplicativeDo BangPatterns BinaryLiterals BlockArguments ConstraintKinds DataKinds DefaultSignatures DeriveAnyClass DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingStrategies DerivingVia DuplicateRecordFields EmptyCase ExistentialQuantification FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving ImportQualifiedPost InstanceSigs KindSignatures LambdaCase LiberalTypeSynonyms MultiParamTypeClasses MultiWayIf NamedFieldPuns NoStarIsType OverloadedLabels OverloadedStrings PackageImports PatternSynonyms PolyKinds QuantifiedConstraints QuasiQuotes RankNTypes RecordWildCards RoleAnnotations ScopedTypeVariables StandaloneDeriving StandaloneKindSignatures StrictData TupleSections TypeApplications TypeFamilies TypeFamilyDependencies TypeOperators UnliftedNewtypes ViewPatterns
24+
default-extensions: AllowAmbiguousTypes ApplicativeDo BangPatterns BinaryLiterals BlockArguments ConstraintKinds DataKinds DefaultSignatures DeriveAnyClass DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingStrategies DerivingVia DuplicateRecordFields EmptyCase ExistentialQuantification FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving ImportQualifiedPost InstanceSigs KindSignatures LambdaCase LiberalTypeSynonyms MultiParamTypeClasses MultiWayIf NamedFieldPuns NoStarIsType OverloadedLabels OverloadedStrings PackageImports PatternSynonyms PolyKinds QuantifiedConstraints QuasiQuotes RankNTypes RecordWildCards RoleAnnotations ScopedTypeVariables StandaloneDeriving StandaloneKindSignatures StrictData TemplateHaskell TupleSections TypeApplications TypeFamilies TypeFamilyDependencies TypeOperators UnliftedNewtypes ViewPatterns
2525
ghc-options: -Wall -Werror -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wmissing-deriving-strategies -Wunused-packages -Wwarn=unused-packages -fhide-source-paths -fno-warn-name-shadowing
2626
default-language: Haskell2010
2727

@@ -36,10 +36,7 @@ library
3636
build-tool-depends:
3737
autoexporter:autoexporter >= 1.1
3838
build-depends:
39-
relude >= 0.7
40-
, bytestring >= 0.10
41-
, text >= 1.2
42-
, containers >= 0.6
39+
relude >= 1.0
4340
, transformers >= 0.5
4441
, random >= 1.2
4542
, filepath >= 1.4
@@ -52,15 +49,15 @@ library
5249
, aeson >= 1.5
5350
, lens-aeson >= 1.1
5451
, time >= 1.9
55-
, yasi >= 0.1
52+
, yasi >= 0.1.1
5653
, binary >= 0.8
5754
, exceptions >= 0.10
5855
, unliftio >= 0.2
5956
, conduit >= 1.3
6057
, conduit-extra >= 1.3
6158
, binary-conduit >= 1.3
6259
, broadcast-chan-conduit >= 0.2
63-
, lens >= 4.19
60+
, lens >= 5.0
6461
, generic-lens >= 2.0
6562
, pcre2 >= 1.1
6663
, cryptohash-sha1 >= 0.11

src/HellSmack/Curse.hs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ downloadFullModpack ModpackInstallOptions {..} = do
117117
\ModLoaderInfo {id} -> logInfo $ [i|mod loader: ${}|] $ C.formatWith [C.bold] id
118118

119119
let (optionalFileIds, requiredFileIds) =
120-
manifest ^. #files
121-
<&> do \f -> (chosen %~ (^. #fileID)) . bool Left Right (f ^. #required) $ f
122-
& partitionEithers
120+
manifest ^. #files & partitionWith \f ->
121+
(chosen %~ (^. #fileID)) . bool Left Right (f ^. #required) $ f
123122

124123
logInfo $ [i|fetching metadata of $show mods|] $ length requiredFileIds
125124
files <- getAddonFilesByFileIds requiredFileIds <&> (^.. each . folded)
126125

127-
logInfo "downloading mods"
126+
let modSize = showBytes' $ sumOf (each . #fileLength) files
127+
logInfo $ [i|downloading mods ($modSize)|]
128128
let modDir = outDir </> [reldir|mods|]
129129
ensureDir modDir
130130
stepWise (withGenericProgress (length files)) \step ->
@@ -290,11 +290,9 @@ findInCurseDB inputs = do
290290
M.fromList . (^.. #exactMatches . each . to ((^. #file . #packageFingerprint) &&& identity))
291291
<$> getFingerprintMatches (fst <$> fps)
292292
let result@(unknown, _) =
293-
fps <&> do
294-
\(fp, path) -> case fpms ^? ix fp of
295-
Just FingerprintMatch {..} -> Right (id, file, path)
296-
Nothing -> Left path
297-
& partitionEithers
293+
fps & partitionWith \(fp, path) -> case fpms ^? ix fp of
294+
Just FingerprintMatch {..} -> Right (id, file, path)
295+
Nothing -> Left path
298296
unless (null unknown) do
299297
logWarn $ [i|these ${show} files are not present in the CurseForge mod database:|] $ length unknown
300298
for_ unknown $ logWarn . [i| - ${}|] . toFilePath

src/HellSmack/Forge.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,9 @@ preprocess fv vvm im = do
345345
Left _ -> do
346346
logInfo "starting forge preprocessing"
347347
let (embedded, downloadable) =
348-
partitionEithers $
349-
im ^. #libraries <&> \case
350-
l | l & has do #downloads . #artifact . _Just . #url . only "" -> Left l
351-
l -> Right l
348+
im ^. #libraries & partitionWith \case
349+
l | l & has do #downloads . #artifact . _Just . #url . only "" -> Left l
350+
l -> Right l
352351
libDir <- siehs @DirConfig #libraryDir
353352
forOf_ (each . #downloads . #artifact . _Just . #path) embedded \fp ->
354353
extractFromInstaller' fv ([reldir|maven|] </> fp) (libDir </> fp)

src/HellSmack/Util/Terminal.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Text.Printf (printf)
3737
import UnliftIO.Async
3838
import UnliftIO.Concurrent
3939
import UnliftIO.Exception
40-
import UnliftIO.IO
40+
import UnliftIO.IO (hIsTerminalDevice)
4141

4242
showBytes :: Integral a => a -> a -> Text
4343
showBytes (fromIntegral -> ref :: Double) (fromIntegral -> a :: Double) =
@@ -119,15 +119,15 @@ withProgress showN' maxCount cb =
119119
Nothing -> 80
120120
countRef <- newIORef 0
121121
start <- currentTime
122-
let withProgressBar = withAsyncWithUnmask \unmask -> forever do
122+
let withProgressBar = withAsyncWithUnmask \unmask -> infinitely do
123123
count <- readIORef countRef
124124
diff <- diffAbsoluteTime <$> currentTime <*> pure start
125125
let p = round @Double $ fromIntegral count / fromIntegral maxCount * fromIntegral barLength
126126
fW c = C.formatWith [c]
127127
bar = fW C.green (T.replicate p "#") <> fW C.blue (T.replicate (barLength - p) "-")
128128
putTextLn $ barTxt diff bar count
129129
unmask (threadDelay printTickMicros) `finally` clearLastLines 1
130-
withProgressBar \_ -> cb $ modifyIORef' countRef
130+
withProgressBar \_ -> cb $ atomicModifyIORef'_ countRef
131131
False -> cb $ const pass
132132
where
133133
barTxt diff bar count = [i|[$diffTxt] $bar ${} / ${}|] (showN count) (showN maxCount)

src/HellSmack/Yggdrasil/API.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ data YggdrasilException = YggdrasilException
3030
cause :: Maybe Text
3131
}
3232
deriving stock (Show, Generic)
33-
deriving anyclass (Exception, FromJSON)
33+
deriving anyclass (FromJSON)
34+
35+
instance Exception YggdrasilException where
36+
displayException YggdrasilException {..} =
37+
[i|Yggdrasil authentication error: $errorMessage ($error$causeMsg)|]
38+
where
39+
causeMsg = maybe "" [iT|, caused by ${}|] cause
3440

3541
newtype AccessToken = AccessToken {unAccessToken :: Text}
3642
deriving stock (Show, Eq, Generic)

src/Main.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE TemplateHaskell #-}
21
{-# LANGUAGE NoMonoLocalBinds #-}
32
{-# LANGUAGE NoMonomorphismRestriction #-}
43

@@ -21,14 +20,14 @@ import HellSmack.Yggdrasil
2120
import Main.Utf8 (withUtf8)
2221
import Options.Applicative qualified as OA
2322
import Path.IO
24-
import System.Exit hiding (exitFailure)
23+
import System.Exit (ExitCode (..))
2524
import UnliftIO.Exception
2625

2726
main :: IO ()
2827
main =
2928
withUtf8 . displayErrors $ do
3029
-- TODO use some open product thingy (cf. jrec branch)
31-
getArgs >>= \CLI {..} -> do
30+
getCLI >>= \CLI {..} -> do
3231
dataDir <- maybe defaultDataDir makeSomeAbsolute dataDir
3332
ensureDir dataDir
3433
let authPath = dataDir </> [relfile|auth.json|]
@@ -145,8 +144,8 @@ data ModOptions
145144
| ModDeduplicate Curse.ModDeduplicateOptions
146145
deriving stock (Show, Generic)
147146

148-
getArgs :: IO CLI
149-
getArgs = OA.execParser $ OA.info (OA.helper <*> ver <*> cliParser) OA.fullDesc
147+
getCLI :: IO CLI
148+
getCLI = OA.execParser $ OA.info (OA.helper <*> ver <*> cliParser) OA.fullDesc
150149
where
151150
ver = OA.infoOption (toString verStr) do
152151
OA.short 'V' <> OA.long "version" <> OA.help "Print version"

src/Prelude.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ import Data.Generics.Labels as P ()
66
import Data.Generics.Wrapped as P
77
import Path as P hiding ((<.>))
88
import Relude as P hiding (uncons, (??))
9-
import Relude.Extra.Enum as P
109
import Relude.Extra.Tuple as P
1110
import Yasi as P

0 commit comments

Comments
 (0)