command-definition.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_TOOLS_NFDC_COMMAND_DEFINITION_HPP
27 #define NFD_TOOLS_NFDC_COMMAND_DEFINITION_HPP
28 
29 #include "command-arguments.hpp"
30 
31 namespace nfd {
32 namespace tools {
33 namespace nfdc {
34 
37 enum class ArgValueType {
43  NONE,
44 
50  ANY,
51 
56  BOOLEAN,
57 
63  UNSIGNED,
64 
69  STRING,
70 
76 
81  NAME,
82 
87  FACE_URI,
88 
94 
100 
105  ROUTE_ORIGIN,
106 };
107 
108 std::ostream&
109 operator<<(std::ostream& os, ArgValueType vt);
110 
113 enum class Required {
114  NO = false,
115  YES = true
116 };
117 
120 enum class Positional {
121  NO = false,
122  YES = true
123 };
124 
128 {
129 public:
130  class Error : public std::invalid_argument
131  {
132  public:
133  using std::invalid_argument::invalid_argument;
134  };
135 
136  CommandDefinition(const std::string& noun, const std::string& verb);
137 
139 
140  const std::string
141  getNoun() const
142  {
143  return m_noun;
144  }
145 
146  const std::string
147  getVerb() const
148  {
149  return m_verb;
150  }
151 
152 public: // help
155  const std::string&
156  getTitle() const
157  {
158  return m_title;
159  }
160 
165  setTitle(const std::string& title)
166  {
167  m_title = title;
168  return *this;
169  }
170 
171 public: // arguments
180  addArg(const std::string& name, ArgValueType valueType,
181  Required isRequired = Required::NO,
182  Positional allowPositional = Positional::NO,
183  const std::string& metavar = "");
184 
191  parse(const std::vector<std::string>& tokens, size_t start = 0) const;
192 
193 private:
194  ndn::any
195  parseValue(ArgValueType valueType, const std::string& token) const;
196 
197 private:
198  std::string m_noun;
199  std::string m_verb;
200  std::string m_title;
201 
202  struct Arg
203  {
204  std::string name;
205  ArgValueType valueType;
206  bool isRequired;
207  std::string metavar;
208  };
209  std::map<std::string, Arg> m_args;
210  std::set<std::string> m_requiredArgs;
211  std::vector<std::string> m_positionalArgs;
212 };
213 
214 } // namespace nfdc
215 } // namespace tools
216 } // namespace nfd
217 
218 #endif // NFD_TOOLS_NFDC_COMMAND_DEFINITION_HPP
boolean argument without value
Required
indicates whether an argument is required
declares semantics of a command
ArgValueType
indicates argument value type
std::ostream & operator<<(std::ostream &os, ArgValueType vt)
CommandDefinition & setTitle(const std::string &title)
set one-line description
const std::string & getTitle() const
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
contains named command arguments
face persistency &#39;persistent&#39; or &#39;permanent&#39;
argument is required
argument is optional
report format &#39;xml&#39; or &#39;text&#39;
Positional
indicates whether an argument can be specified as positional