diff --git a/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs b/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs index 9d492d6d41..fe95eb12c5 100644 --- a/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Byron/Parsers.hs @@ -24,7 +24,7 @@ module Cardano.CLI.Byron.Parsers ) where -import Cardano.Api hiding (GenesisParameters, UpdateProposal) +import Cardano.Api hiding (GenesisParameters, UpdateProposal, parseFilePath) import Cardano.Api.Byron (Address (..), ByronProtocolParametersUpdate (..), toByronLovelace) import qualified Cardano.Api.Ledger as L diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 89bd183a50..0d4e8679c3 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -12,9 +12,9 @@ module Cardano.CLI.EraBased.Options.Common where -import Cardano.Api +import Cardano.Api hiding (bounded, parseFilePath) import qualified Cardano.Api.Ledger as L -import Cardano.Api.Shelley +import Cardano.Api.Shelley hiding (bounded, parseFilePath) import Cardano.CLI.Environment (EnvCli (..), envCliAnyShelleyBasedEra, envCliAnyShelleyToBabbageEra) @@ -26,7 +26,7 @@ import Cardano.CLI.Types.Key import Cardano.CLI.Types.Key.VerificationKey import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as Consensus -import Control.Monad (mfilter, void) +import Control.Monad (mfilter, void, when) import qualified Data.Aeson as Aeson import Data.Bifunctor import Data.Bits (Bits, toIntegralSized) @@ -55,6 +55,7 @@ import qualified Text.Parsec.Error as Parsec import qualified Text.Parsec.Language as Parsec import qualified Text.Parsec.String as Parsec import qualified Text.Parsec.Token as Parsec +import qualified Text.Read as Read import Text.Read (readEither, readMaybe) command' :: String -> String -> Parser a -> Mod CommandFields a @@ -72,6 +73,22 @@ prefixFlag prefix longFlag = Nothing -> longFlag Just prefix' -> prefix' <> "-" <> longFlag +bounded :: forall a. (Bounded a, Integral a, Show a) => String -> Opt.ReadM a +bounded t = Opt.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) + +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") + ) + pNetworkIdDeprecated :: Parser NetworkId pNetworkIdDeprecated = asum diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs index 458fdebbbf..b427bad9f3 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs @@ -9,7 +9,7 @@ module Cardano.CLI.EraBased.Options.Genesis ) where -import Cardano.Api hiding (QueryInShelleyBasedEra (..)) +import Cardano.Api hiding (QueryInShelleyBasedEra (..), parseFilePath) import Cardano.Api.Ledger (Coin (..)) import Cardano.Chain.Common (BlockCount (BlockCount)) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs index 443d78b8c3..58520058db 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs @@ -8,7 +8,7 @@ module Cardano.CLI.EraBased.Options.Key ) where -import Cardano.Api hiding (QueryInShelleyBasedEra (..)) +import Cardano.Api hiding (QueryInShelleyBasedEra (..), parseFilePath) import Cardano.CLI.EraBased.Commands.Key import Cardano.CLI.EraBased.Options.Common diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs index 44156d7200..f5e5a22bba 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs @@ -21,9 +21,9 @@ module Cardano.CLI.Legacy.Options ) where -import Cardano.Api hiding (QueryInShelleyBasedEra (..)) +import Cardano.Api hiding (QueryInShelleyBasedEra (..), parseFilePath) import Cardano.Api.Ledger (Coin (..)) -import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..)) +import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..), parseFilePath) import Cardano.Chain.Common (BlockCount (BlockCount)) import Cardano.CLI.Environment diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Legacy/Options/Key.hs index 9bddcb229a..4448343f99 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Options/Key.hs @@ -8,7 +8,7 @@ module Cardano.CLI.Legacy.Options.Key ) where -import Cardano.Api hiding (QueryInShelleyBasedEra (..)) +import Cardano.Api hiding (QueryInShelleyBasedEra (..), parseFilePath) import Cardano.CLI.EraBased.Options.Common import Cardano.CLI.Legacy.Commands.Key diff --git a/cardano-cli/src/Cardano/CLI/Options/Debug.hs b/cardano-cli/src/Cardano/CLI/Options/Debug.hs index 36fa113efc..a7ecbf9a3a 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Debug.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Debug.hs @@ -11,7 +11,7 @@ module Cardano.CLI.Options.Debug ) where -import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..)) +import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..), parseFilePath) import Cardano.CLI.Commands.Debug import Cardano.CLI.Commands.Debug.LogEpochState