cardano-wallet-cli-2022.7.1: Utilities for a building Command-Line Interfaces
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 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

cmdWallet :: ( ToJSON wallet, CmdWalletUpdatePassphrase wallet) => CmdWalletCreate wallet -> WalletClient wallet -> Mod CommandFields ( IO ()) Source #

Option & Argument Parsers

optionT :: FromText a => Mod OptionFields a -> Parser a Source #

Helper for writing an option Parser using a FromText instance.

argumentT :: FromText a => Mod ArgumentFields a -> Parser a Source #

Helper for writing an argument Parser using a FromText instance.

hostPreferenceOption :: Parser HostPreference Source #

--listen-address=HOSTSPEC
, default: 127.0.0.1

stateDirOption :: FilePath -> Parser ( Maybe FilePath ) Source #

  • -state-dir=DIR, default: ~ .cardano-wallet $backend/$network

syncToleranceOption :: Parser SyncTolerance Source #

  • -sync-tolerance=DURATION, default: 300s

metadataOption :: Parser ( Maybe TxMetadataWithSchema ) Source #

--metadata=JSON

Note: we decode the JSON just so that we can validate more client-side.

Option parsers for configuring tracing

data LogOutput Source #

Constructors

LogToStdStreams Severity

Log to console, with the given minimum Severity .

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.

loggingSeverities :: [( String , Severity)] Source #

The lower-case names of all Severity values.

Types

newtype Port (tag :: Symbol ) Source #

Port number with a tag for describing what it is used for

Constructors

Port

Instances

Instances details
Bounded ( Port tag) Source #
Instance details

Defined in Cardano.CLI

Enum ( Port tag) Source #
Instance details

Defined in Cardano.CLI

Eq ( Port tag) Source #
Instance details

Defined in Cardano.CLI

Ord ( Port tag) Source #
Instance details

Defined in Cardano.CLI

Show ( Port tag) Source #
Instance details

Defined in Cardano.CLI

Generic ( Port tag) Source #
Instance details

Defined in Cardano.CLI

Associated Types

type Rep ( Port tag) :: Type -> Type Source #

FromText ( Port tag) Source #
Instance details

Defined in Cardano.CLI

ToText ( Port tag) Source #
Instance details

Defined in Cardano.CLI

type Rep ( Port tag) Source #
Instance details

Defined in Cardano.CLI

type Rep ( Port tag) = D1 (' MetaData "Port" "Cardano.CLI" "cardano-wallet-cli-2022.7.1-7I5cmzvoh385voCHyGQArG" ' True ) ( C1 (' MetaCons "Port" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getPort") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Int )))

Logging

withLogging :: [ LogOutput ] -> ((Switchboard Text , (Configuration, Trace IO Text )) -> IO a) -> IO a Source #

withLoggingNamed Source #

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

putErrLn :: Text -> IO () Source #

Like hPutErrLn but with provided default Handle

hPutErrLn :: Handle -> Text -> IO () Source #

Print an error message in red

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

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.

getSensitiveLine Source #

Arguments

:: Buildable e
=> Text

A message to prompt the user

-> ( Text -> Either e a)

An explicit parser from Text

-> 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.

getDataDir Source #

Arguments

:: String

The network backend name.

-> IO FilePath

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