Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
Cardano.CLI
Description
Shared types and helpers for CLI parsing
Synopsis
- cli :: Mod CommandFields a -> ParserInfo a
- runCli :: ParserInfo ( IO ()) -> IO ()
- cmdMnemonic :: Mod CommandFields ( IO ())
- cmdWallet :: ( ToJSON wallet, CmdWalletUpdatePassphrase wallet) => CmdWalletCreate wallet -> WalletClient wallet -> Mod CommandFields ( IO ())
- cmdWalletCreate :: WalletClient ApiWallet -> Mod CommandFields ( IO ())
- cmdByronWalletCreate :: WalletClient ApiByronWallet -> Mod CommandFields ( IO ())
- cmdTransaction :: ToJSON wallet => TransactionClient -> WalletClient wallet -> Mod CommandFields ( IO ())
- cmdAddress :: AddressClient -> Mod CommandFields ( IO ())
- cmdStakePool :: ToJSON apiPool => StakePoolClient apiPool -> Mod CommandFields ( IO ())
- cmdNetwork :: NetworkClient -> Mod CommandFields ( IO ())
- cmdVersion :: Mod CommandFields ( IO ())
- cmdKey :: Mod CommandFields ( IO ())
- optionT :: FromText a => Mod OptionFields a -> Parser a
- argumentT :: FromText a => Mod ArgumentFields a -> Parser a
- databaseOption :: Parser FilePath
- hostPreferenceOption :: Parser HostPreference
- listenOption :: Parser Listen
- shutdownHandlerFlag :: Parser Bool
- stateDirOption :: FilePath -> Parser ( Maybe FilePath )
- syncToleranceOption :: Parser SyncTolerance
- tlsOption :: Parser TlsConfiguration
- poolMetadataSourceOption :: Parser PoolMetadataSource
- tokenMetadataSourceOption :: Parser TokenMetadataServer
- metadataOption :: Parser ( Maybe TxMetadataWithSchema )
- timeToLiveOption :: Parser ( Maybe ( Quantity "second" NominalDiffTime ))
-
data
LoggingOptions
tracers =
LoggingOptions
{
- loggingMinSeverity :: Severity
- loggingTracers :: tracers
- loggingTracersDoc :: Maybe Void
-
data
LogOutput
- = LogToStdStreams Severity
- | LogToFile FilePath Severity
- helperTracing :: [( String , String )] -> Parser (a -> a)
- loggingOptions :: Parser tracers -> Parser ( LoggingOptions tracers)
- loggingSeverities :: [( String , Severity)]
- parseLoggingSeverity :: String -> Either String Severity
- loggingSeverityOrOffReader :: ReadM ( Maybe Severity)
- loggingSeverityReader :: ReadM Severity
- data Service
- data TxId
- newtype Port (tag :: Symbol ) = Port { }
- withLogging :: [ LogOutput ] -> ((Switchboard Text , (Configuration, Trace IO Text )) -> IO a) -> IO a
- withLoggingNamed :: LoggerName -> [ LogOutput ] -> ((Switchboard Text , (Configuration, Trace IO Text )) -> IO a) -> IO a
- putErrLn :: Text -> IO ()
- hPutErrLn :: Handle -> Text -> IO ()
- enableWindowsANSI :: IO ()
- getLine :: Text -> ( Text -> Either String a) -> IO (a, Text )
- hGetLine :: Buildable e => ( Handle , Handle ) -> Text -> ( Text -> Either e a) -> IO (a, Text )
- getSensitiveLine :: Buildable e => Text -> ( Text -> Either e a) -> IO (a, Text )
- hGetSensitiveLine :: Buildable e => ( Handle , Handle ) -> Text -> ( Text -> Either e a) -> IO (a, Text )
- decodeError :: ByteString -> Maybe Text
- requireFilePath :: FilePath -> IO ()
- getDataDir :: String -> IO FilePath
- setupDirectory :: ( Text -> IO ()) -> FilePath -> IO ()
- getPrometheusURL :: IO ( Maybe ( String , Port "Prometheus"))
- getEKGURL :: IO ( Maybe ( String , Port "EKG"))
- ekgEnabled :: IO Bool
CLI Execution
cli :: Mod CommandFields a -> ParserInfo a Source #
Construct a CLI from a list of a commands
>>>
runCli $ cli $ cmdA <> cmdB <> cmdC
runCli :: ParserInfo ( IO ()) -> IO () Source #
Runs a specific command parser using appropriate preferences
Commands
cmdMnemonic :: Mod CommandFields ( IO ()) Source #
cmdWallet :: ( ToJSON wallet, CmdWalletUpdatePassphrase wallet) => CmdWalletCreate wallet -> WalletClient wallet -> Mod CommandFields ( IO ()) Source #
cmdWalletCreate :: WalletClient ApiWallet -> Mod CommandFields ( IO ()) Source #
cmdByronWalletCreate :: WalletClient ApiByronWallet -> Mod CommandFields ( IO ()) Source #
cmdTransaction :: ToJSON wallet => TransactionClient -> WalletClient wallet -> Mod CommandFields ( IO ()) Source #
cardano-wallet transaction
cmdAddress :: AddressClient -> Mod CommandFields ( IO ()) Source #
cmdStakePool :: ToJSON apiPool => StakePoolClient apiPool -> Mod CommandFields ( IO ()) Source #
cmdNetwork :: NetworkClient -> Mod CommandFields ( IO ()) Source #
cmdVersion :: Mod CommandFields ( IO ()) Source #
Option & Argument Parsers
databaseOption :: Parser FilePath Source #
- -database=DIR
hostPreferenceOption :: Parser HostPreference Source #
- --listen-address=HOSTSPEC
- , default: 127.0.0.1
listenOption :: Parser Listen Source #
- --random-port|--port=INT
shutdownHandlerFlag :: Parser Bool Source #
- --shutdown-handler
stateDirOption :: FilePath -> Parser ( Maybe FilePath ) Source #
- -state-dir=DIR, default: ~ .cardano-wallet $backend/$network
syncToleranceOption :: Parser SyncTolerance Source #
- -sync-tolerance=DURATION, default: 300s
tokenMetadataSourceOption :: Parser TokenMetadataServer Source #
- --token-metadata-server=URL
metadataOption :: Parser ( Maybe TxMetadataWithSchema ) Source #
- --metadata=JSON
Note: we decode the JSON just so that we can validate more client-side.
timeToLiveOption :: Parser ( Maybe ( Quantity "second" NominalDiffTime )) Source #
- --ttl=DURATION
Option parsers for configuring tracing
data LoggingOptions tracers Source #
Constructors
LoggingOptions | |
Fields
|
Instances
Eq tracers => Eq ( LoggingOptions tracers) Source # | |
Defined in Cardano.CLI Methods (==) :: LoggingOptions tracers -> LoggingOptions tracers -> Bool Source # (/=) :: LoggingOptions tracers -> LoggingOptions tracers -> Bool Source # |
|
Show tracers => Show ( LoggingOptions tracers) Source # | |
Defined in Cardano.CLI |
Constructors
LogToStdStreams Severity |
Log to console, with the given minimum
Logs of Warning or higher severity will be output to stderr. Notice or lower severity logs will be output to stdout. |
LogToFile FilePath Severity |
helperTracing :: [( String , String )] -> Parser (a -> a) Source #
A hidden "helper" option which always fails, but shows info about the logging options.
loggingOptions :: Parser tracers -> Parser ( LoggingOptions tracers) Source #
loggingSeverities :: [( String , Severity)] Source #
The lower-case names of all
Severity
values.
loggingSeverityOrOffReader :: ReadM ( Maybe Severity) Source #
loggingSeverityReader :: ReadM Severity Source #
Types
Wrapper type around
Text
to make its semantic more explicit
newtype Port (tag :: Symbol ) Source #
Port number with a tag for describing what it is used for
Instances
Bounded ( Port tag) Source # | |
Enum ( Port tag) Source # | |
Defined in Cardano.CLI Methods succ :: Port tag -> Port tag Source # pred :: Port tag -> Port tag Source # toEnum :: Int -> Port tag Source # fromEnum :: Port tag -> Int Source # enumFrom :: Port tag -> [ Port tag] Source # enumFromThen :: Port tag -> Port tag -> [ Port tag] Source # enumFromTo :: Port tag -> Port tag -> [ Port tag] Source # enumFromThenTo :: Port tag -> Port tag -> Port tag -> [ Port tag] Source # |
|
Eq ( Port tag) Source # | |
Ord ( Port tag) Source # | |
Defined in Cardano.CLI |
|
Show ( Port tag) Source # | |
Generic ( Port tag) Source # | |
FromText ( Port tag) Source # | |
Defined in Cardano.CLI |
|
ToText ( Port tag) Source # | |
type Rep ( Port tag) Source # | |
Defined in Cardano.CLI |
Logging
withLogging :: [ LogOutput ] -> ((Switchboard Text , (Configuration, Trace IO Text )) -> IO a) -> IO a Source #
See
withLoggingNamed
Arguments
:: LoggerName | |
-> [ LogOutput ] | |
-> ((Switchboard Text , (Configuration, Trace IO Text )) -> IO a) |
The action to run with logging configured. |
-> IO a |
Run an action with logging available and configured. When the action is finished (normally or otherwise), log messages are flushed.
ANSI Terminal Helpers
enableWindowsANSI :: IO () Source #
The IOHK logging framework prints out ANSI colour codes with its messages.
On Windows 10 and above it's possible to enable processing of these colour
codes. The
hSupportsANSIWithoutEmulation
function does this as a side
effect. On older versions of Windows, special treatment is required (see:
ANSI
). In this case, this function will achieve nothing, and
the ANSI control characters will be printed in grey (too bad).
Working with Sensitive Data
getLine :: Text -> ( Text -> Either String a) -> IO (a, Text ) Source #
Like
hGetLine
but with default handles
hGetLine :: Buildable e => ( Handle , Handle ) -> Text -> ( Text -> Either e a) -> IO (a, Text ) Source #
Prompt user and parse the input. Re-prompt on invalid inputs.
Arguments
:: Buildable e | |
=> Text |
A message to prompt the user |
-> ( Text -> Either e a) |
An explicit parser from
|
-> IO (a, Text ) |
Like
hGetSensitiveLine
but with default handles
hGetSensitiveLine :: Buildable e => ( Handle , Handle ) -> Text -> ( Text -> Either e a) -> IO (a, Text ) Source #
Gather user inputs until a newline is met, hiding what's typed with a placeholder character.
Helpers
decodeError :: ByteString -> Maybe Text Source #
Decode API error messages and extract the corresponding message.
requireFilePath :: FilePath -> IO () Source #
Look whether a particular filepath is correctly resolved on the filesystem. This makes for a better user experience when passing wrong filepaths via options or arguments, especially when they get forwarded to other services.
Find the user data directory for a given node network backend.
setupDirectory :: ( Text -> IO ()) -> FilePath -> IO () Source #
Initialize a directory to store data such as blocks or the wallet databases
ekgEnabled :: IO Bool Source #