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)
48 shortopts.push_back(
':');
50 longopts[i].name = strdup(params[i].key.c_str());
51 longopts[i].has_arg = params[i].is_switch ? no_argument : required_argument;
52 longopts[i].flag = NULL;
53 longopts[i].val = params[i].short_key;
60 while ((c = getopt_long(argc, argv, shortopts.c_str(), longopts, &idx))
63 for (
unsigned i = 0; i < params.size(); ++i) {
64 if (c == params[i].short_key) {
66 if (!params[i].is_switch) {
70 result.
Set(params[i], argument);
79 for (
unsigned i = 0; i < params.size(); ++i) {
80 free(const_cast<char *>(longopts[i].name));
85 GetName() +
": unrecognized parameter '" + argv[optind - 1] +
"'",
86 EPublish::kFailInvocation);
90 for (
unsigned i = 0; i < params.size(); ++i) {
91 free(const_cast<char *>(longopts[i].name));
95 for (
unsigned i = 0; i < params.size(); ++i) {
96 if (!params[i].is_optional && !result.
Has(params[i].key)) {
98 GetName() +
": missing mandatory parameter '" + params[i].key +
"'",
99 EPublish::kFailInvocation);
103 for (
int i = optind; i < argc; ++i) {
107 if (result.
plain_args().size() < GetMinPlainArgs()) {
109 GetName().c_str(), GetUsage().c_str());
110 throw EPublish(GetName() +
": missing argument", EPublish::kFailInvocation);
120 CommandList::~CommandList() {
121 for (
unsigned i = 0; i < commands_.size(); ++i)
125 Command *CommandList::Find(
const std::string &name) {
127 for (
unsigned i = 0; i < commands_.size(); ++i) {
128 if (commands_[i]->GetName() == name) {
129 result = commands_[i];
136 void CommandList::TakeCommand(
Command *command) {
138 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,...)