hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
iroha_cli::interactive Namespace Reference

Classes

class  InteractiveCli
 
class  InteractiveQueryCli
 
class  InteractiveStatusCli
 
class  InteractiveTransactionCli
 
struct  ParamData
 

Typedefs

using ParamsDescription = std::vector< ParamData >
 
using DescriptionMap = std::unordered_map< std::string, std::string >
 
using MenuPoints = std::vector< std::string >
 
using ParamsMap = std::unordered_map< std::string, ParamsDescription >
 

Enumerations

enum  MenuContext { MAIN, RESULT }
 

Functions

DescriptionMap getCommonDescriptionMap ()
 
ParamsMap getCommonParamsMap (const std::string &default_ip, int default_port)
 
ParamsDescription makeParamsDescription (const std::vector< std::string > &params)
 
void handleEmptyCommand ()
 
void handleUnknownCommand (std::string &command)
 
void addBackOption (MenuPoints &menu)
 
bool isBackOption (std::string line)
 
void printCommandParameters (std::string &command, const ParamsDescription &parameters)
 
void printMenu (const std::string &message, MenuPoints menu_points)
 
boost::optional< std::string > promptString (const std::string &message)
 
boost::optional< std::string > promptString (const ParamData &param)
 
void printEnd ()
 
boost::optional< std::pair< std::string, uint16_t > > parseIrohaPeerParams (std::vector< std::string > params, const std::string &default_ip, int default_port)
 
boost::optional< std::vector< std::string > > parseParams (std::string line, std::string command_name, ParamsMap &params_map)
 
size_t addMenuPoint (std::vector< std::string > &menu_points, const std::string &description, const std::string &command_short_name)
 
static void printMenu (const MenuPoints &menu)
 
template<typename K , typename V >
std::size_t getNextIndex (std::unordered_map< K, V > parsers_map)
 
template<typename K , typename V >
boost::optional< V & > findInHandlerMap (K command_name, std::unordered_map< K, V > &params_map)
 
template<typename T , typename V , typename C >
boost::optional< T > handleParse (C class_pointer, std::string &line, std::unordered_map< std::string, V > &parsers_map, ParamsMap &params_map)
 
template<typename V >
void addCliCommand (MenuPoints &menu_points, std::unordered_map< std::string, V > &parsers_map, const std::string &command_name, const std::string &command_description, V parser)
 
template<typename V >
MenuPoints formMenu (std::unordered_map< std::string, V > &parsers_map, ParamsMap &paramsMap, const DescriptionMap descriptionMap)
 

Variables

static const std::map< iroha::protocol::TxStatus, std::string > userMessageMap
 
const std::string SAVE_CODE = "save"
 
const std::string SEND_CODE = "send"
 
const std::string BACK_CODE = "b"
 

Typedef Documentation

using iroha_cli::interactive::DescriptionMap = typedef std::unordered_map<std::string, std::string>
using iroha_cli::interactive::MenuPoints = typedef std::vector<std::string>
using iroha_cli::interactive::ParamsMap = typedef std::unordered_map<std::string, ParamsDescription>

Enumeration Type Documentation

Parsing menu context, used to identify the context of parsing

Enumerator
MAIN 

Main menu context, used to print all commands/queries

RESULT 

Result menu, used for send, save tx/query

Function Documentation

void iroha_cli::interactive::addBackOption ( MenuPoints menu)

Add back option to menu

Parameters
menu- menu to add the back option

Here is the caller graph for this function:

template<typename V >
void iroha_cli::interactive::addCliCommand ( MenuPoints menu_points,
std::unordered_map< std::string, V > &  parsers_map,
const std::string &  command_name,
const std::string &  command_description,
parser 
)

Add new cli command to menu points and menu handlers (parsers)

Template Parameters
Vtype of parser functions in parsers_map
Parameters
menu_points- menu to which points will be added
parsers_map- map holding specific parser functions
command_name- short command name
command_description- description for the command
parser- specific parser for current command

Here is the call graph for this function:

size_t iroha_cli::interactive::addMenuPoint ( std::vector< std::string > &  menu_points,
const std::string &  description,
const std::string &  command_short_name 
)

Add menu point to vector menu

Parameters
menu_pointsto add new point
descriptionof the command to add
command_short_namecommand short name

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename K , typename V >
boost::optional<V &> iroha_cli::interactive::findInHandlerMap ( command_name,
std::unordered_map< K, V > &  params_map 
)

Find in unordered map with error reporting. Will print unkown command if key not found.

Template Parameters
Kkey type
Vvalue type
Parameters
command_name- key to find in the map
params_map- map
Returns
nullopt if key not found, value if found

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename V >
MenuPoints iroha_cli::interactive::formMenu ( std::unordered_map< std::string, V > &  parsers_map,
ParamsMap paramsMap,
const DescriptionMap  descriptionMap 
)

Form menu points from given parameters and bind index of the command with their parser and parameters

Template Parameters
V- type of specific parser functions in parsers_map
Parameters
parsers_map- map holding specific parser functions
paramsMap- map holding descriptions for command parameters
descriptionMap- map holding description of a command
Returns
Formed menu points

Here is the call graph for this function:

Here is the caller graph for this function:

DescriptionMap iroha_cli::interactive::getCommonDescriptionMap ( )

Return mapping of Command_name to Command description

Returns
DesciptionMap for common commands

Here is the caller graph for this function:

ParamsMap iroha_cli::interactive::getCommonParamsMap ( const std::string &  default_ip,
int  default_port 
)

Return mapping of Command_name to parameters descriptions

Parameters
default_ip- default hostname or IP to be used when connecting to irohad
default_port- default port to be used when connecting to irohad
Returns
ParamsMap with parameters of common commands

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename K , typename V >
std::size_t iroha_cli::interactive::getNextIndex ( std::unordered_map< K, V >  parsers_map)

Get next numerical index in the map. Used to build menu

Template Parameters
K- key type in map
V- value type in map
Parameters
parsers_map- map to process
Returns
index for the next menu point
void iroha_cli::interactive::handleEmptyCommand ( )

Handle error with empty command

Here is the caller graph for this function:

template<typename T , typename V , typename C >
boost::optional<T> iroha_cli::interactive::handleParse ( class_pointer,
std::string &  line,
std::unordered_map< std::string, V > &  parsers_map,
ParamsMap params_map 
)

Handle parsing routine:

  • find appropriate parser function for the command
  • get input from user for the command
  • trigger specific parser
    Template Parameters
    T- expected return type of a parsing function
    V- type of the parser function in parsers_map
    C- class type of class_pointer
    Parameters
    class_pointer- class pointer that holds parser functions
    line- line to parse
    parsers_map- map holding parser functions
    params_map- map holding descriptions for command parameters
    Returns
    T if parsing successful, nullopt otherwise

Here is the call graph for this function:

void iroha_cli::interactive::handleUnknownCommand ( std::string &  command)

Handle error of unknown command

Parameters
command- name of unknown command

Here is the caller graph for this function:

bool iroha_cli::interactive::isBackOption ( std::string  line)

Is line contains "Go Back" option

Parameters
lineto parse
Returns
true if line has command "go back"

Here is the call graph for this function:

Here is the caller graph for this function:

ParamsDescription iroha_cli::interactive::makeParamsDescription ( const std::vector< std::string > &  params)

Creates parameters descriptions with empty default/cache values

Parameters
params- parameters as a vector of prompt messages
Returns
ParamsDescription with parameter data

Here is the caller graph for this function:

boost::optional< std::pair< std::string, uint16_t > > iroha_cli::interactive::parseIrohaPeerParams ( std::vector< std::string >  params,
const std::string &  default_ip,
int  default_port 
)

Parse parameters related to Iroha Peer

Parameters
paramsin format: vector of strings
Returns
pair if ip and port if formed right, nullopt otherwise

Here is the caller graph for this function:

boost::optional< std::vector< std::string > > iroha_cli::interactive::parseParams ( std::string  line,
std::string  command_name,
ParamsMap params_map 
)

Parse parameters in interactive and shortcuted mode. Function run interactive mode if in line only the command name is passed. Function will parse all needed parameters from line if the line with commands is passed, it will print help if there are not enough parameters in line.

Parameters
line- cli line to parse
command_name- command name to print
notes- parameters needed to run the command
Returns
vector with needed parameters

Here is the call graph for this function:

Here is the caller graph for this function:

void iroha_cli::interactive::printCommandParameters ( std::string &  command,
const ParamsDescription parameters 
)

Print help for cli command.

Parameters
command- name of the cli command
parametersneeded to run the command

Here is the caller graph for this function:

void iroha_cli::interactive::printEnd ( )

Print end of session symbol

Here is the caller graph for this function:

void iroha_cli::interactive::printMenu ( const std::string &  message,
MenuPoints  menu_points 
)

Pretty Print of menu

Parameters
message- message to print before menu
menu_points- elements of the menu

Here is the caller graph for this function:

static void iroha_cli::interactive::printMenu ( const MenuPoints menu)
static

Here is the call graph for this function:

boost::optional< std::string > iroha_cli::interactive::promptString ( const std::string &  message)

Get string input from user

Parameters
messageMessage to ask user
Returns
nullopt if termintaing symbol, else user's input

Here is the caller graph for this function:

boost::optional< std::string > iroha_cli::interactive::promptString ( const ParamData param)

Construct a prompt and get a string input from user

Parameters
paramParameter to collect the input for
Returns
nullopt if termintaing symbol, else user's input

Here is the call graph for this function:

Variable Documentation

const std::string iroha_cli::interactive::BACK_CODE = "b"
const std::string iroha_cli::interactive::SAVE_CODE = "save"
const std::string iroha_cli::interactive::SEND_CODE = "send"
const std::map<iroha::protocol::TxStatus, std::string> iroha_cli::interactive::userMessageMap
static
Initial value:
= {
{iroha::protocol::TxStatus::STATELESS_VALIDATION_FAILED,
"Transaction has not passed stateless validation."},
{iroha::protocol::TxStatus::STATELESS_VALIDATION_SUCCESS,
"Transaction has successfully passed stateless validation."},
{iroha::protocol::TxStatus::STATEFUL_VALIDATION_FAILED,
"Transaction has not passed stateful validation."},
{iroha::protocol::TxStatus::STATEFUL_VALIDATION_SUCCESS,
"Transaction has successfully passed stateful validation."},
{iroha::protocol::TxStatus::REJECTED,
"Transaction has been rejected."},
{iroha::protocol::TxStatus::COMMITTED,
"Transaction was successfully committed."},
{iroha::protocol::TxStatus::MST_EXPIRED,
"Transaction has not collected enough signatures in time."},
{iroha::protocol::TxStatus::NOT_RECEIVED,
"Transaction was not found in the system."},
{iroha::protocol::TxStatus::MST_PENDING,
"Transaction has not collected quorum of signatures."},
{iroha::protocol::TxStatus::ENOUGH_SIGNATURES_COLLECTED,
"Transaction has collected all signatures."}}