diff --git a/package.yaml b/package.yaml index ef815764..dcf95a00 100644 --- a/package.yaml +++ b/package.yaml @@ -57,7 +57,6 @@ library: - microlens - microlens-mtl - opt-env-conf - - optparse-applicative - path - relude - semigroups diff --git a/restyler.cabal b/restyler.cabal index fc889d34..ba367e15 100644 --- a/restyler.cabal +++ b/restyler.cabal @@ -34,7 +34,6 @@ library Restyler.Monad.Git Restyler.Monad.ReadFile Restyler.Monad.WriteFile - Restyler.Opt Restyler.Options Restyler.Options.DryRun Restyler.Options.FailOnDifferences @@ -96,7 +95,6 @@ library , microlens , microlens-mtl , opt-env-conf - , optparse-applicative , path , relude , semigroups diff --git a/src/Restyler/AnnotatedException.hs b/src/Restyler/AnnotatedException.hs index 658702f0..884a3664 100644 --- a/src/Restyler/AnnotatedException.hs +++ b/src/Restyler/AnnotatedException.hs @@ -17,10 +17,6 @@ module Restyler.AnnotatedException , hide , displayAnnotatedException - -- * Annotated-safe handling - , handleTo - , tryTo - -- * Suppressing exception , suppressWith , suppressWarn @@ -39,17 +35,6 @@ displayAnnotatedException aex@AnnotatedException {exception} = , maybe "" (pack . prettyCallStack) $ annotatedExceptionCallStack aex ] -handleTo - :: (MonadUnliftIO m, Exception e1, Exception e2) => (e1 -> e2) -> m a -> m a -handleTo f action = do - r <- tryAnnotated action - case r of - Left AnnotatedException {exception} -> throw $ f exception - Right a -> pure a - -tryTo :: (MonadUnliftIO m, Exception e) => (e -> b) -> m a -> m (Either b a) -tryTo f = fmap (first $ f . exception) . tryAnnotated - -- | Suppress any exception and return the given @a@ suppressWith :: MonadUnliftIO m => a -> m a -> m a suppressWith x = either (const $ pure x) pure <=< tryAnnotated @SomeException diff --git a/src/Restyler/Opt.hs b/src/Restyler/Opt.hs deleted file mode 100644 index 0d8b95e3..00000000 --- a/src/Restyler/Opt.hs +++ /dev/null @@ -1,49 +0,0 @@ --- | --- --- Module : Restyler.Opt --- Copyright : (c) 2024 Patrick Brisbin --- License : AGPL-3 --- Maintainer : pbrisbin@gmail.com --- Stability : experimental --- Portability : POSIX -module Restyler.Opt - ( parse - , module Options.Applicative - ) -where - -import Restyler.Prelude - -import Data.List qualified as List -import Options.Applicative -import Options.Applicative.Help.Chunk - -parse - :: String - -- ^ Description - -> String - -- ^ Footer - -> Parser a - -- ^ Options parser - -> IO a -parse d f p = - execParser - $ info (p <**> helper) - $ fullDesc - <> progDesc d - <> footerLines f - --- | --- --- The 'footer' function takes a string, but then makes it a doc with --- 'paragraph' which replaces all newlines with spaces. Fun. This function --- preserves newlines at least, so the simple case of a pre-pretty-printed --- string is hanlded somewhat better. -footerLines :: String -> InfoMod a -footerLines = - footerDoc - . Just - . extractChunk - . vcatChunks - . map stringChunk - . List.lines diff --git a/src/Restyler/Prelude.hs b/src/Restyler/Prelude.hs index 9d34362a..e20b08ac 100644 --- a/src/Restyler/Prelude.hs +++ b/src/Restyler/Prelude.hs @@ -36,10 +36,7 @@ import UnliftIO.Exception as X (finally) import UnliftIO.Temporary as X (withSystemTempDirectory) import Blammo.Logging.Logger (flushLogger) -import Data.Aeson (Key) -import Data.Aeson.KeyMap (KeyMap) -import Data.Aeson.KeyMap qualified as KeyMap -import Data.List (minimum, minimumBy, (!!)) +import Data.List (minimum) logTrace :: (MonadLogger m, HasCallStack) => Message -> m () logTrace = logOther $ LevelOther "trace" @@ -66,22 +63,6 @@ minimumMaybe = \case [] -> Nothing xs -> Just $ minimum xs -minimumByMaybe :: (a -> a -> Ordering) -> [a] -> Maybe a -minimumByMaybe f = \case - [] -> Nothing - xs -> Just $ minimumBy f xs - --- | Safe version of '(!!)' -(!?) :: [a] -> Int -> Maybe a -xs !? i - | length xs > i = Just $ xs !! i - | otherwise = Nothing - -infixl 9 !? - -- | Inverse of @'any'@ none :: Foldable t => (a -> Bool) -> t a -> Bool none p = not . any p - -insertIfMissing :: Key -> v -> KeyMap v -> KeyMap v -insertIfMissing k v m = KeyMap.unionWith const m $ KeyMap.singleton k v