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_fsbroker_CommandInterpreter_h
28 #define Tools_client_fsbroker_CommandInterpreter_h
29 
30 #include <FsBroker/Lib/Client.h>
31 
33 
34 #include "AsyncComm/Comm.h"
35 
36 #include <memory>
37 #include <string>
38 #include <unordered_map>
39 
40 using namespace Hypertable;
41 
42 namespace Tools {
43 namespace client {
44 namespace fsbroker {
45 
48 
51  public:
52 
59  CommandInterpreter(FsBroker::Lib::ClientPtr &client, bool nowait=false)
60  : m_client(client), m_nowait(nowait) {
61  load_help_text();
62  };
63 
64  int execute_line(const String &line) override;
65 
66  private:
67 
68  class ParseResult {
69  public:
70  void clear();
71  int32_t command {};
72  std::vector<std::string> args;
73  int64_t offset {};
74  };
75 
79  void parse_line(const String &line, ParseResult &result) const;
80 
83  void load_help_text();
84 
89  void display_help_text(const std::string &command) const;
90 
95  void display_usage(const std::string &command) const;
96 
97  void parse_error(const std::string &command) const;
98 
101 
103  std::unordered_map<std::string, const char **> m_help_text;
104 
106  bool m_nowait {};
107  };
108 
110  typedef std::shared_ptr<CommandInterpreter> CommandInterpreterPtr;
111 
113 
114 }}}
115 
116 #endif // Tools_client_fsbroker_CommandInterpreter_h
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Definition: Client.h:233
std::shared_ptr< CommandInterpreter > CommandInterpreterPtr
Hypertable definitions
FsBroker::Lib::ClientPtr m_client
File system client.
Declarations for Comm.
CommandInterpreter(FsBroker::Lib::ClientPtr &client, bool nowait=false)
Constructor.
Forward declarations.
std::unordered_map< std::string, const char ** > m_help_text
Map of help text.
Declarations for Client.
Command interpreter for ht_fsbroker.