LCOV - code coverage report
Current view: top level - iroha-cli/interactive/impl - interactive_cli.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 0 60 0.0 %
Date: 2019-03-07 14:46:43 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "interactive/interactive_cli.hpp"
       7             : 
       8             : #include <ciso646>
       9             : #include <utility>
      10             : 
      11             : #include "logger/logger_manager.hpp"
      12             : 
      13             : namespace iroha_cli {
      14             :   namespace interactive {
      15             : 
      16             :     void InteractiveCli::assign_main_handlers() {
      17           0 :       addCliCommand(menu_points_,
      18           0 :                     main_handler_map_,
      19           0 :                     TX_CODE,
      20           0 :                     "New transaction",
      21             :                     &InteractiveCli::startTx);
      22           0 :       addCliCommand(menu_points_,
      23           0 :                     main_handler_map_,
      24           0 :                     QRY_CODE,
      25           0 :                     "New query",
      26             :                     &InteractiveCli::startQuery);
      27           0 :       addCliCommand(menu_points_,
      28           0 :                     main_handler_map_,
      29           0 :                     ST_CODE,
      30           0 :                     "New transaction status request",
      31             :                     &InteractiveCli::startTxStatusRequest);
      32           0 :     }
      33             : 
      34             :     InteractiveCli::InteractiveCli(
      35             :         const std::string &account_name,
      36             :         const std::string &default_peer_ip,
      37             :         int default_port,
      38             :         uint64_t qry_counter,
      39             :         const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider,
      40             :         logger::LoggerManagerTreePtr response_handler_log_manager,
      41             :         logger::LoggerPtr pb_qry_factory_log,
      42             :         logger::LoggerPtr json_qry_factory_log,
      43             :         logger::LoggerManagerTreePtr log_manager)
      44           0 :         : creator_(account_name),
      45           0 :           tx_cli_(creator_,
      46           0 :                   default_peer_ip,
      47           0 :                   default_port,
      48           0 :                   provider,
      49           0 :                   response_handler_log_manager,
      50           0 :                   pb_qry_factory_log,
      51           0 :                   log_manager->getChild("Transaction")->getLogger()),
      52           0 :           query_cli_(creator_,
      53           0 :                      default_peer_ip,
      54           0 :                      default_port,
      55           0 :                      qry_counter,
      56           0 :                      provider,
      57           0 :                      std::move(response_handler_log_manager),
      58           0 :                      pb_qry_factory_log,
      59           0 :                      std::move(json_qry_factory_log),
      60           0 :                      log_manager->getChild("Query")->getLogger()),
      61           0 :           statusCli_(
      62           0 :               default_peer_ip, default_port, std::move(pb_qry_factory_log)) {
      63           0 :       assign_main_handlers();
      64           0 :     }
      65             : 
      66             :     void InteractiveCli::parseMain(std::string line) {
      67           0 :       auto raw_command = parser::parseFirstCommand(std::move(line));
      68           0 :       if (not raw_command) {
      69           0 :         handleEmptyCommand();
      70           0 :         return;
      71             :       }
      72           0 :       auto command_name = *raw_command;
      73           0 : 
      74           0 :       auto val = findInHandlerMap(command_name, main_handler_map_);
      75           0 :       if (val) {
      76           0 :         (this->*val.value())();
      77           0 :       }
      78           0 :     }
      79             : 
      80             :     void InteractiveCli::startQuery() {
      81           0 :       query_cli_.run();
      82           0 :     }
      83             : 
      84             :     void InteractiveCli::startTx() {
      85           0 :       tx_cli_.run();
      86           0 :     }
      87             : 
      88             :     void InteractiveCli::startTxStatusRequest() {
      89           0 :       statusCli_.run();
      90           0 :     }
      91             : 
      92             :     void InteractiveCli::run() {
      93           0 :       std::cout << "Welcome to Iroha-Cli. " << std::endl;
      94             :       // Parsing cycle
      95           0 :       while (true) {
      96           0 :         printMenu("Choose what to do:", menu_points_);
      97           0 :         auto line = promptString("> ");
      98           0 :         if (not line) {
      99             :           // Line contains terminating symbol
     100           0 :           break;
     101             :         }
     102           0 :         parseMain(line.value());
     103           0 :       }
     104           0 :     }
     105             : 
     106             :   }  // namespace interactive
     107             : }  // namespace iroha_cli

Generated by: LCOV version 1.13