5 #include "cvmfs_config.h"
23 std::string Command::GetExamples()
const {
24 std::vector<std::string> examples = DoGetExamples();
26 for (
unsigned i = 0; i < examples.size(); ++i) {
27 result += progname() +
" " + GetName() +
" " + examples[i] +
"\n";
39 struct option *longopts =
reinterpret_cast<option *
>(
40 smalloc((params.size() + 1) *
sizeof(
struct option)));
41 struct option lastopt;
42 memset(&lastopt, 0,
sizeof(lastopt));
43 longopts[params.size()] = lastopt;
45 for (
unsigned i = 0; i < params.size(); ++i) {
46 shortopts.push_back(params[i].short_key);
47 if (!params[i].is_switch) shortopts.push_back(
':');
49 longopts[i].name = strdup(params[i].key.c_str());
50 longopts[i].has_arg = params[i].is_switch ? no_argument : required_argument;
51 longopts[i].flag = NULL;
52 longopts[i].val = params[i].short_key;
59 while ((c = getopt_long(argc, argv, shortopts.c_str(), longopts, &idx)) != -1)
62 for (
unsigned i = 0; i < params.size(); ++i) {
63 if (c == params[i].short_key) {
65 if (!params[i].is_switch) {
69 result.
Set(params[i], argument);
78 for (
unsigned i = 0; i < params.size(); ++i) {
79 free(const_cast<char *>(longopts[i].name));
83 throw EPublish(GetName() +
": unrecognized parameter '" +
84 argv[optind - 1] +
"'", EPublish::kFailInvocation);
88 for (
unsigned i = 0; i < params.size(); ++i) {
89 free(const_cast<char *>(longopts[i].name));
93 for (
unsigned i = 0; i < params.size(); ++i) {
94 if (!params[i].is_optional && !result.
Has(params[i].key)) {
96 GetName() +
": missing mandatory parameter '" + params[i].key +
"'",
97 EPublish::kFailInvocation);
101 for (
int i = optind; i < argc; ++i) {
105 if (result.
plain_args().size() < GetMinPlainArgs()) {
107 progname().c_str(), GetName().c_str(), GetUsage().c_str());
108 throw EPublish(GetName() +
": missing argument", EPublish::kFailInvocation);
118 CommandList::~CommandList() {
119 for (
unsigned i = 0; i < commands_.size(); ++i)
123 Command *CommandList::Find(
const std::string &name) {
125 for (
unsigned i = 0; i < commands_.size(); ++i) {
126 if (commands_[i]->GetName() == name) {
127 result = commands_[i];
134 void CommandList::TakeCommand(
Command *command) {
136 commands_.push_back(command);
bool Has(const std::string &key) const
assert((mem||(size==0))&&"Out Of Memory")
const std::vector< Argument > & plain_args() const
int64_t String2Int64(const string &value)
std::vector< Parameter > ParameterList
void Set(const Parameter &p, const Argument &a)
void AppendPlain(const Argument &a)
virtual std::string GetName() const =0
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)