0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
InteractiveCommand.h
Go to the documentation of this file.
1 /*
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; either version 3
9  * of the 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 #ifndef HYPERTABLE_INTERACTIVECOMMAND_H
27 #define HYPERTABLE_INTERACTIVECOMMAND_H
28 
29 #include <cstring>
30 
31 #include <utility>
32 #include <vector>
33 
34 namespace Hypertable {
35 
46  public:
48  virtual ~InteractiveCommand() { }
49 
55  void parse_command_line(const char *line);
56 
59  bool matches(const char *line) {
60  return !strncmp(line, command_text(), strlen(command_text()));
61  }
62 
67  virtual const char *command_text() = 0;
68 
73  virtual const char **usage() = 0;
74 
76  virtual void run() = 0;
77 
79  void clear_args() { m_args.clear(); }
80 
82  void push_arg(std::string key, std::string value) {
83  m_args.push_back(std::pair<std::string, std::string>(key, value));
84  }
85 
86  protected:
88  std::vector< std::pair<std::string, std::string> > m_args;
89 
91  bool parse_string_literal(const char *str, std::string &text,
92  const char **endptr);
93 };
94 
97 }
98 
99 #endif // HYPERTABLE_INTERACTIVECOMMAND_H
virtual const char * command_text()=0
Returns the command text (i.e.
void push_arg(std::string key, std::string value)
Append another key/value pair to the argument list.
virtual const char ** usage()=0
Returns the usage string.
bool parse_string_literal(const char *str, std::string &text, const char **endptr)
Helper function to parse a string literal.
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
Abstract base class for simple interactive shell commands.
virtual void run()=0
Runs the command; can access the command line arguments in m_args.
virtual ~InteractiveCommand()
Virtual destructor can be overwritten in subclasses.
bool matches(const char *line)
Returns true if the command_text() matches the command line.
void clear_args()
Clears all arguments.
std::vector< std::pair< std::string, std::string > > m_args
The vector with key/value pairs for this command.
Hypertable definitions
void parse_command_line(const char *line)
Parses a command line and stores the arguments in m_args.