BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
cli.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <fc/io/stdio.hpp>
3 #include <fc/io/json.hpp>
5 #include <fc/io/sstream.hpp>
7 #include <fc/thread/thread.hpp>
8 
9 #include <iostream>
10 
11 namespace fc { namespace rpc {
12 
16  class cli : public api_connection
17  {
18  public:
19  cli( uint32_t max_depth ) : api_connection(max_depth) {}
20  ~cli();
21 
22  virtual variant send_call( api_id_type api_id, string method_name, variants args = variants() );
23  virtual variant send_callback( uint64_t callback_id, variants args = variants() );
24  virtual void send_notice( uint64_t callback_id, variants args = variants() );
25 
26  void start();
27  void stop();
28  void cancel();
29  void wait();
30  void format_result( const string& method, std::function<string(variant,const variants&)> formatter);
31 
32  virtual void getline( const std::string& prompt, std::string& line );
33 
34  void set_prompt( const string& prompt );
35 
36  void set_regex_secret( const string& expr );
37 
38  private:
39  void run();
40 
41  std::string _prompt = ">>>";
42  std::map<string,std::function<string(variant,const variants&)> > _result_formatters;
43  fc::future<void> _run_complete;
44  fc::thread* _getline_thread = nullptr;
45  };
46 } }
void set_prompt(const string &prompt)
Definition: cli.cpp:62
void stop()
Definition: cli.cpp:287
std::vector< variant > variants
Definition: variant.hpp:170
virtual void send_notice(uint64_t callback_id, variants args=variants())
Definition: cli.cpp:52
void start()
Definition: cli.cpp:252
void set_regex_secret(const string &expr)
Definition: cli.cpp:67
cli(uint32_t max_depth)
Definition: cli.hpp:19
void format_result(const string &method, std::function< string(variant, const variants &)> formatter)
Definition: cli.cpp:57
virtual variant send_call(api_id_type api_id, string method_name, variants args=variants())
Definition: cli.cpp:42
void cancel()
Definition: cli.cpp:274
void wait()
Definition: cli.cpp:293
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
uint32_t api_id_type
Definition: api.hpp:122
Definition: api.hpp:15
virtual variant send_callback(uint64_t callback_id, variants args=variants())
Definition: cli.cpp:47
virtual void getline(const std::string &prompt, std::string &line)
Definition: cli.cpp:303