From 93173daad0bdfa9a843d36bcfc59feef3a79eac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 12 Sep 2024 14:20:53 +0200 Subject: [PATCH 1/2] Remove optparse-applicative-fork dependency, and functions depending on it --- cardano-api/cardano-api.cabal | 1 - cardano-api/internal/Cardano/Api/Utils.hs | 23 ----------------------- cardano-api/src/Cardano/Api.hs | 4 ---- 3 files changed, 28 deletions(-) diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index b98778ace9..010bb3da82 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -197,7 +197,6 @@ library internal microlens-aeson, mtl, network, - optparse-applicative-fork, ouroboros-consensus ^>=0.20, ouroboros-consensus-cardano ^>=0.19, ouroboros-consensus-diffusion ^>=0.17, diff --git a/cardano-api/internal/Cardano/Api/Utils.hs b/cardano-api/internal/Cardano/Api/Utils.hs index f0afd2619b..3eb0f22ba2 100644 --- a/cardano-api/internal/Cardano/Api/Utils.hs +++ b/cardano-api/internal/Cardano/Api/Utils.hs @@ -19,14 +19,12 @@ module Cardano.Api.Utils , failEitherWith , noInlineMaybeToStrictMaybe , note - , parseFilePath , readFileBlocking , runParsecParser , textShow , modifyWith -- ** CLI option parsing - , bounded , unsafeBoundedRational ) where @@ -34,7 +32,6 @@ where import Cardano.Ledger.BaseTypes import Cardano.Ledger.Shelley () import Control.Exception (bracket) -import Control.Monad (when) import qualified Data.Aeson.Types as Aeson import qualified Data.ByteString as BS import qualified Data.ByteString.Builder as Builder @@ -45,14 +42,10 @@ import qualified Data.Text as Text import Data.Typeable import GHC.IO.Handle.FD (openFileBlocking) import GHC.Stack -import Options.Applicative (ReadM) -import qualified Options.Applicative as Opt -import Options.Applicative.Builder (eitherReader) import System.IO (IOMode (ReadMode), hClose) import qualified Text.Parsec as Parsec import qualified Text.Parsec.String as Parsec import qualified Text.ParserCombinators.Parsec.Error as Parsec -import qualified Text.Read as Read (?!) :: Maybe a -> e -> Either e a Nothing ?! e = Left e @@ -94,15 +87,6 @@ note msg = \case Nothing -> fail msg Just a -> pure a -parseFilePath :: String -> String -> Opt.Parser FilePath -parseFilePath optname desc = - Opt.strOption - ( Opt.long optname - <> Opt.metavar "FILEPATH" - <> Opt.help desc - <> Opt.completer (Opt.bashCompleter "file") - ) - readFileBlocking :: FilePath -> IO BS.ByteString readFileBlocking path = bracket @@ -123,13 +107,6 @@ readFileBlocking path = textShow :: Show a => a -> Text textShow = Text.pack . show -bounded :: forall a. (Bounded a, Integral a, Show a) => String -> ReadM a -bounded t = eitherReader $ \s -> do - i <- Read.readEither @Integer s - when (i < fromIntegral (minBound @a)) $ Left $ t <> " must not be less than " <> show (minBound @a) - when (i > fromIntegral (maxBound @a)) $ Left $ t <> " must not greater than " <> show (maxBound @a) - pure (fromIntegral i) - -- | Aids type inference. Use this function to ensure the value is a function -- that modifies a value. modifyWith diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 6b720e3877..c168cc0cc9 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -926,7 +926,6 @@ module Cardano.Api , chainPointToSlotNo , chainPointToHeaderHash , makeChainTip - , parseFilePath , writeSecrets -- * Convenience functions @@ -949,9 +948,6 @@ module Cardano.Api , notScriptLockedTxIns , textShow - -- ** CLI option parsing - , bounded - -- ** Query expressions , queryAccountState , queryChainBlockNo From 356e83e1c0f68a7b870b548c55075d33a137376f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 12 Sep 2024 14:23:06 +0200 Subject: [PATCH 2/2] Remove an unused function --- cardano-api/internal/Cardano/Api/Utils.hs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Utils.hs b/cardano-api/internal/Cardano/Api/Utils.hs index 3eb0f22ba2..3c8d7cc28a 100644 --- a/cardano-api/internal/Cardano/Api/Utils.hs +++ b/cardano-api/internal/Cardano/Api/Utils.hs @@ -22,7 +22,6 @@ module Cardano.Api.Utils , readFileBlocking , runParsecParser , textShow - , modifyWith -- ** CLI option parsing , unsafeBoundedRational @@ -107,14 +106,6 @@ readFileBlocking path = textShow :: Show a => a -> Text textShow = Text.pack . show --- | Aids type inference. Use this function to ensure the value is a function --- that modifies a value. -modifyWith - :: () - => (a -> a) - -> (a -> a) -modifyWith = id - -- | Convert Rational to a bounded rational. Throw an exception when the rational is out of bounds. unsafeBoundedRational :: forall r