module Hydra.TUI.Options where
import Hydra.Prelude
import Data.Version (Version (Version), showVersion)
import Hydra.API.ServerOutput (ApiEncoding (..))
import Hydra.Cardano.Api (NetworkId, SocketPath)
import Hydra.Network (Host (Host))
import Hydra.Options (networkIdParser)
import Hydra.Version (embeddedRevision, gitRevision, unknownVersion)
import Options.Applicative (
Parser,
auto,
flag,
help,
infoOption,
long,
metavar,
option,
short,
showDefault,
strOption,
value,
)
import Paths_hydra_tui (version)
data Options = Options
{ Options -> Host
hydraNodeHost :: Host
, Options -> Either FilePath SocketPath
cardanoConnection :: Either FilePath SocketPath
, Options -> NetworkId
cardanoNetworkId :: NetworkId
, Options -> FilePath
fundsSigningKey :: FilePath
, Options -> Maybe FilePath
fuelVerificationKey :: Maybe FilePath
, Options -> ApiEncoding
apiEncoding :: ApiEncoding
}
deriving stock (Options -> Options -> Bool
(Options -> Options -> Bool)
-> (Options -> Options -> Bool) -> Eq Options
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Options -> Options -> Bool
== :: Options -> Options -> Bool
$c/= :: Options -> Options -> Bool
/= :: Options -> Options -> Bool
Eq, Int -> Options -> ShowS
[Options] -> ShowS
Options -> FilePath
(Int -> Options -> ShowS)
-> (Options -> FilePath) -> ([Options] -> ShowS) -> Show Options
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Options -> ShowS
showsPrec :: Int -> Options -> ShowS
$cshow :: Options -> FilePath
show :: Options -> FilePath
$cshowList :: [Options] -> ShowS
showList :: [Options] -> ShowS
Show)
parseOptions :: Parser Options
parseOptions :: Parser Options
parseOptions =
( Host
-> Either FilePath SocketPath
-> NetworkId
-> FilePath
-> Maybe FilePath
-> ApiEncoding
-> Options
Options
(Host
-> Either FilePath SocketPath
-> NetworkId
-> FilePath
-> Maybe FilePath
-> ApiEncoding
-> Options)
-> Parser Host
-> Parser
(Either FilePath SocketPath
-> NetworkId
-> FilePath
-> Maybe FilePath
-> ApiEncoding
-> Options)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Host
parseNodeHost
Parser
(Either FilePath SocketPath
-> NetworkId
-> FilePath
-> Maybe FilePath
-> ApiEncoding
-> Options)
-> Parser (Either FilePath SocketPath)
-> Parser
(NetworkId -> FilePath -> Maybe FilePath -> ApiEncoding -> Options)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Either FilePath SocketPath)
parsecardanoConnection
Parser
(NetworkId -> FilePath -> Maybe FilePath -> ApiEncoding -> Options)
-> Parser NetworkId
-> Parser (FilePath -> Maybe FilePath -> ApiEncoding -> Options)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser NetworkId
networkIdParser
Parser (FilePath -> Maybe FilePath -> ApiEncoding -> Options)
-> Parser FilePath
-> Parser (Maybe FilePath -> ApiEncoding -> Options)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath
parseFundsSigningKey
Parser (Maybe FilePath -> ApiEncoding -> Options)
-> Parser (Maybe FilePath) -> Parser (ApiEncoding -> Options)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Maybe FilePath)
parseFuelVerificationKey
Parser (ApiEncoding -> Options)
-> Parser ApiEncoding -> Parser Options
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ApiEncoding
parseApiEncoding
)
Parser Options -> Parser (Options -> Options) -> Parser Options
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> Parser (Options -> Options)
versionInfo
where
versionInfo :: Parser (Options -> Options)
versionInfo :: Parser (Options -> Options)
versionInfo =
FilePath
-> Mod OptionFields (Options -> Options)
-> Parser (Options -> Options)
forall a. FilePath -> Mod OptionFields (a -> a) -> Parser (a -> a)
infoOption
(Version -> FilePath
showVersion Version
ourVersion)
(FilePath -> Mod OptionFields (Options -> Options)
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"version" Mod OptionFields (Options -> Options)
-> Mod OptionFields (Options -> Options)
-> Mod OptionFields (Options -> Options)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields (Options -> Options)
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Show version")
ourVersion :: Version
ourVersion =
Version
version Version -> (Version -> Version) -> Version
forall a b. a -> (a -> b) -> b
& \(Version [Int]
semver [FilePath]
_) -> [Int] -> [FilePath] -> Version
Version [Int]
semver [FilePath]
revision
revision :: [FilePath]
revision =
Maybe FilePath -> [FilePath]
forall a. Maybe a -> [a]
maybeToList (Maybe FilePath -> [FilePath]) -> Maybe FilePath -> [FilePath]
forall a b. (a -> b) -> a -> b
$
Maybe FilePath
embeddedRevision
Maybe FilePath -> Maybe FilePath -> Maybe FilePath
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe FilePath
gitRevision
Maybe FilePath -> Maybe FilePath -> Maybe FilePath
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
unknownVersion
parsecardanoConnection :: Parser (Either FilePath SocketPath)
parsecardanoConnection :: Parser (Either FilePath SocketPath)
parsecardanoConnection = SocketPath -> Either FilePath SocketPath
forall a b. b -> Either a b
Right (SocketPath -> Either FilePath SocketPath)
-> Parser SocketPath -> Parser (Either FilePath SocketPath)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser SocketPath
cardanoNodeSocket Parser (Either FilePath SocketPath)
-> Parser (Either FilePath SocketPath)
-> Parser (Either FilePath SocketPath)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath -> Either FilePath SocketPath
forall a b. a -> Either a b
Left (FilePath -> Either FilePath SocketPath)
-> Parser FilePath -> Parser (Either FilePath SocketPath)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FilePath
blockFrost
where
cardanoNodeSocket :: Parser SocketPath
cardanoNodeSocket :: Parser SocketPath
cardanoNodeSocket =
Mod OptionFields SocketPath -> Parser SocketPath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
( FilePath -> Mod OptionFields SocketPath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"node-socket"
Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields SocketPath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE"
Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields SocketPath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"The path to the Cardano node domain socket for client communication."
Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> SocketPath -> Mod OptionFields SocketPath
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value SocketPath
"node.socket"
Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields SocketPath
forall a (f :: * -> *). Show a => Mod f a
showDefault
)
blockFrost :: Parser FilePath
blockFrost :: Parser FilePath
blockFrost =
Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
( FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"blockfrost"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"The path to the Blockfrost project file."
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value FilePath
"blockfrost-project.txt"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields FilePath
forall a (f :: * -> *). Show a => Mod f a
showDefault
)
parseNodeHost :: Parser Host
parseNodeHost :: Parser Host
parseNodeHost =
ReadM Host -> Mod OptionFields Host -> Parser Host
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
ReadM Host
forall a. Read a => ReadM a
auto
( FilePath -> Mod OptionFields Host
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"connect"
Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Host
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'c'
Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields Host
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Hydra-node to connect to in the form of <host>:<port>"
Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> Host -> Mod OptionFields Host
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value (Text -> PortNumber -> Host
Host Text
"127.0.0.1" PortNumber
4001)
Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields Host
forall a (f :: * -> *). Show a => Mod f a
showDefault
)
parseFundsSigningKey :: Parser FilePath
parseFundsSigningKey :: Parser FilePath
parseFundsSigningKey =
Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
( FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"funds-signing-key"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'k'
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"The path to the funds signing key file used for selecting UTxO and signing a commit transaction. This file uses the same 'TextEnvelope' format as cardano-cli."
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value FilePath
"me.sk"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields FilePath
forall a (f :: * -> *). Show a => Mod f a
showDefault
)
parseApiEncoding :: Parser ApiEncoding
parseApiEncoding :: Parser ApiEncoding
parseApiEncoding =
ApiEncoding
-> ApiEncoding -> Mod FlagFields ApiEncoding -> Parser ApiEncoding
forall a. a -> a -> Mod FlagFields a -> Parser a
flag
ApiEncoding
JsonEncoding
ApiEncoding
CborEncoding
( FilePath -> Mod FlagFields ApiEncoding
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"cbor"
Mod FlagFields ApiEncoding
-> Mod FlagFields ApiEncoding -> Mod FlagFields ApiEncoding
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod FlagFields ApiEncoding
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Use the binary CBOR encoding on the WebSocket connection to the hydra-node instead of JSON."
)
parseFuelVerificationKey :: Parser (Maybe FilePath)
parseFuelVerificationKey :: Parser (Maybe FilePath)
parseFuelVerificationKey =
Parser FilePath -> Parser (Maybe FilePath)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser FilePath -> Parser (Maybe FilePath))
-> Parser FilePath -> Parser (Maybe FilePath)
forall a b. (a -> b) -> a -> b
$
Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
( FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"fuel-key"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILE"
Mod OptionFields FilePath
-> Mod OptionFields FilePath -> Mod OptionFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"The path to the verification key file of the hydra-node's internal wallet. When provided, the Funds tab shows the node's available fuel (UTxO usable to pay for layer 1 protocol transactions). This fuel is display-only and never used to commit. Uses the same 'TextEnvelope' format as cardano-cli."
)