Skip to content

Commit

Permalink
Merge pull request #635 from IntersectMBO/smelc/remove-opt-parse-depe…
Browse files Browse the repository at this point in the history
…ndency

Remove optparse-applicative-fork dependency, and functions depending on it
  • Loading branch information
smelc authored Sep 12, 2024
2 parents bf84187 + 356e83e commit eb2108c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 37 deletions.
1 change: 0 additions & 1 deletion cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 0 additions & 32 deletions cardano-api/internal/Cardano/Api/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@ module Cardano.Api.Utils
, failEitherWith
, noInlineMaybeToStrictMaybe
, note
, parseFilePath
, readFileBlocking
, runParsecParser
, textShow
, modifyWith

-- ** CLI option parsing
, bounded
, unsafeBoundedRational
)
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
Expand All @@ -45,14 +41,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
Expand Down Expand Up @@ -94,15 +86,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
Expand All @@ -123,21 +106,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
:: ()
=> (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
Expand Down
4 changes: 0 additions & 4 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,6 @@ module Cardano.Api
, chainPointToSlotNo
, chainPointToHeaderHash
, makeChainTip
, parseFilePath
, writeSecrets

-- * Convenience functions
Expand All @@ -949,9 +948,6 @@ module Cardano.Api
, notScriptLockedTxIns
, textShow

-- ** CLI option parsing
, bounded

-- ** Query expressions
, queryAccountState
, queryChainBlockNo
Expand Down

0 comments on commit eb2108c

Please sign in to comment.