0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CommandInterpreter.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef Tools_client_thriftbroker_CommandInterpreter_h
28 #define Tools_client_thriftbroker_CommandInterpreter_h
29 
30 #include <ThriftBroker/Client.h>
31 
33 
34 #include <AsyncComm/Comm.h>
35 
36 #include <memory>
37 #include <string>
38 #include <unordered_map>
39 
40 namespace Tools {
41 namespace client {
42 namespace thriftbroker {
43 
44  using namespace Hypertable;
45 
48 
51  public:
52 
59  CommandInterpreter(Thrift::ClientPtr &client, bool nowait=false)
60  : m_client(client) {
61  (void)nowait;
62  load_help_text();
63  };
64 
65  int execute_line(const String &line) override;
66 
67  private:
68 
69  class ParseResult {
70  public:
71  void clear();
72  int32_t command {};
73  std::vector<std::string> args;
74  int64_t offset {};
75  };
76 
80  void parse_line(const String &line, ParseResult &result) const;
81 
84  void load_help_text();
85 
90  void display_help_text(const std::string &command) const;
91 
96  void display_usage(const std::string &command) const;
97 
98  void parse_error(const std::string &command) const;
99 
102 
104  std::unordered_map<std::string, const char **> m_help_text;
105 
106  };
107 
109  typedef std::shared_ptr<CommandInterpreter> CommandInterpreterPtr;
110 
112 
113 }}}
114 
115 #endif // Tools_client_thriftbroker_CommandInterpreter_h
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
virtual int execute_line(const String &line)=0
CommandInterpreter(Thrift::ClientPtr &client, bool nowait=false)
Constructor.
std::shared_ptr< CommandInterpreter > CommandInterpreterPtr
Smart pointer to CommandInterpreter.
Command interpreter for ht_thriftbroker.
Thrift::ClientPtr m_client
File system client.
Hypertable definitions
Declarations for Comm.
std::shared_ptr< Client > ClientPtr
Smart pointer to client.
Definition: Client.h:84
std::unordered_map< std::string, const char ** > m_help_text
Map of help text.
Forward declarations.