CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_SWISSKNIFE_H_
6 #define CVMFS_SWISSKNIFE_H_
7 
8 #include <cassert>
9 #include <map>
10 #include <string>
11 #include <vector>
12 
13 #include "download.h"
14 #include "manifest_fetch.h"
15 #include "reflog.h"
16 #include "server_tool.h"
17 #include "signature.h"
18 #include "statistics.h"
19 #include "util/shared_ptr.h"
20 
21 namespace download {
22 class DownloadManager;
23 }
24 namespace manifest {
25 class Manifest;
26 }
27 namespace perf {
28 class Statistics;
29 }
30 namespace signature {
31 class SignatureManager;
32 }
33 
34 namespace swissknife {
35 
36 class Parameter {
37  public:
38  static Parameter Mandatory(const char key, const std::string &desc) {
39  return Parameter(key, desc, false, false);
40  }
41  static Parameter Optional(const char key, const std::string &desc) {
42  return Parameter(key, desc, true, false);
43  }
44  static Parameter Switch(const char key, const std::string &desc) {
45  return Parameter(key, desc, true, true);
46  }
47 
48  char key() const { return key_; }
49  const std::string &description() const { return description_; }
50  bool optional() const { return optional_; }
51  bool mandatory() const { return !optional_; }
52  bool switch_only() const { return switch_only_; }
53 
54  protected:
55  Parameter(const char key, const std::string &desc, const bool opt,
56  const bool switch_only)
57  : key_(key),
58  description_(desc),
59  optional_(opt),
60  switch_only_(switch_only) {
61  assert(!switch_only_ || optional_); // switches are optional by definition
62  }
63 
64  private:
65  char key_;
66  std::string description_;
67  bool optional_;
69 };
70 
71 typedef std::vector<Parameter> ParameterList;
72 typedef std::map<char, SharedPtr<std::string> > ArgumentList;
73 
74 class Command : public ServerTool {
75  public:
76  // generic command parameters
77  static const char kGenericParam = '+';
78  static const char kGenericParamSeparator = ',';
79 
80  Command();
81  virtual ~Command();
82  virtual std::string GetName() const = 0;
83  virtual std::string GetDescription() const = 0;
84  virtual ParameterList GetParams() const = 0;
85  virtual int Main(const ArgumentList &args) = 0;
86 };
87 
88 } // namespace swissknife
89 
90 #endif // CVMFS_SWISSKNIFE_H_
static Parameter Optional(const char key, const std::string &desc)
Definition: swissknife.h:41
const manifest::Manifest * manifest() const
Definition: repository.h:123
static Parameter Switch(const char key, const std::string &desc)
Definition: swissknife.h:44
static const char kGenericParamSeparator
Definition: swissknife.h:78
virtual ParameterList GetParams() const =0
virtual ~Command()
Definition: swissknife.cc:27
std::vector< Parameter > ParameterList
Definition: swissknife.h:71
Parameter(const char key, const std::string &desc, const bool opt, const bool switch_only)
Definition: swissknife.h:55
std::string description_
Definition: swissknife.h:66
virtual int Main(const ArgumentList &args)=0
virtual std::string GetDescription() const =0
assert((mem||(size==0))&&"Out Of Memory")
bool switch_only() const
Definition: swissknife.h:52
static Parameter Mandatory(const char key, const std::string &desc)
Definition: swissknife.h:38
const std::string & description() const
Definition: swissknife.h:49
static const char kGenericParam
Definition: swissknife.h:77
bool optional() const
Definition: swissknife.h:50
bool mandatory() const
Definition: swissknife.h:51
std::map< char, SharedPtr< std::string > > ArgumentList
Definition: swissknife.h:72
virtual std::string GetName() const =0
char key() const
Definition: swissknife.h:48