1212
1313module Cardano.CLI.EraBased.Options.Common where
1414
15- import Cardano.Api
15+ import Cardano.Api hiding ( bounded , parseFilePath )
1616import qualified Cardano.Api.Ledger as L
17- import Cardano.Api.Shelley
17+ import Cardano.Api.Shelley hiding ( bounded , parseFilePath )
1818
1919import Cardano.CLI.Environment (EnvCli (.. ), envCliAnyShelleyBasedEra ,
2020 envCliAnyShelleyToBabbageEra )
@@ -26,7 +26,7 @@ import Cardano.CLI.Types.Key
2626import Cardano.CLI.Types.Key.VerificationKey
2727import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as Consensus
2828
29- import Control.Monad (mfilter , void )
29+ import Control.Monad (mfilter , void , when )
3030import qualified Data.Aeson as Aeson
3131import Data.Bifunctor
3232import Data.Bits (Bits , toIntegralSized )
@@ -55,6 +55,7 @@ import qualified Text.Parsec.Error as Parsec
5555import qualified Text.Parsec.Language as Parsec
5656import qualified Text.Parsec.String as Parsec
5757import qualified Text.Parsec.Token as Parsec
58+ import qualified Text.Read as Read
5859import Text.Read (readEither , readMaybe )
5960
6061command' :: String -> String -> Parser a -> Mod CommandFields a
@@ -72,6 +73,22 @@ prefixFlag prefix longFlag =
7273 Nothing -> longFlag
7374 Just prefix' -> prefix' <> " -" <> longFlag
7475
76+ bounded :: forall a . (Bounded a , Integral a , Show a ) => String -> Opt. ReadM a
77+ bounded t = Opt. eitherReader $ \ s -> do
78+ i <- Read. readEither @ Integer s
79+ when (i < fromIntegral (minBound @ a )) $ Left $ t <> " must not be less than " <> show (minBound @ a )
80+ when (i > fromIntegral (maxBound @ a )) $ Left $ t <> " must not greater than " <> show (maxBound @ a )
81+ pure (fromIntegral i)
82+
83+ parseFilePath :: String -> String -> Opt. Parser FilePath
84+ parseFilePath optname desc =
85+ Opt. strOption
86+ ( Opt. long optname
87+ <> Opt. metavar " FILEPATH"
88+ <> Opt. help desc
89+ <> Opt. completer (Opt. bashCompleter " file" )
90+ )
91+
7592pNetworkIdDeprecated :: Parser NetworkId
7693pNetworkIdDeprecated =
7794 asum
0 commit comments