blob: ec5d2167a729342b1ec36df5fbc0f2e9015b563b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "proxycmd.h"
#include "methods.h"
#include <vespa/fastos/app.h>
#include <iostream>
class Application : public FastOS_Application
{
Flags _flags;
bool parseOpts();
public:
void usage();
int Main() override;
Application() : _flags() {}
};
bool
Application::parseOpts()
{
int c = '?';
const char *optArg = NULL;
int optInd = 0;
while ((c = GetOpt("m:s:p:h", optArg, optInd)) != -1) {
switch (c) {
case 'm':
_flags.method = optArg;
break;
case 's':
_flags.targethost = optArg;
break;
case 'p':
_flags.portnumber = atoi(optArg);
break;
case 'h':
default:
return false; // triggers usage()
}
}
const Method method = methods::find(_flags.method);
if (optInd + method.args <= _argc) {
for (int i = 0; i < method.args; ++i) {
vespalib::string arg = _argv[optInd++];
_flags.args.push_back(arg);
}
} else {
std::cerr << "ERROR: method "<< _flags.method << " requires " << method.args
<< " arguments, only got " << (_argc - optInd) << std::endl;
return false;
}
if (optInd != _argc) {
std::cerr << "ERROR: "<<(_argc - optInd)<<" extra arguments\n";
return false;
}
_flags.method = method.rpcMethod;
return true;
}
void
Application::usage(void)
{
std::cerr <<
"Usage: vespa-configproxy-cmd [options]" << std::endl <<
" -m <method> method" << std::endl <<
" -s <hostname> hostname (default: localhost)" << std::endl <<
" -p <port> port number (default: 19090)" << std::endl <<
"Available methods for -m option:" << std::endl;
methods::dump();
}
int
Application::Main(void)
{
if (! parseOpts()) {
usage();
return 1;
}
ProxyCmd client(_flags);
return client.action();
}
int
main(int argc, char** argv)
{
Application app;
return app.Entry(argc, argv);
}
|