1
0
Fork 0

make arangovpack work without any config file specified (#5224)

This commit is contained in:
Jan 2018-04-30 18:33:42 +02:00 committed by GitHub
parent 2870b8f586
commit a7555e0bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 18 deletions

View File

@ -1,6 +1,9 @@
devel
-----
* added `--json` option to arangovpack, allowing to treat its input as plain JSON data
make arangovpack work without any configuration file
* added experimental arangodb startup option `--javascript.enabled` to enable/disable the initialization
of the V8 JavaScript engine. Only expected to work on single-servers and agency deployments

View File

@ -113,6 +113,7 @@ VPackFeature::VPackFeature(application_features::ApplicationServer* server,
: ApplicationFeature(server, "VPack"),
_result(result),
_prettyPrint(true),
_jsonInput(false),
_hexInput(false),
_printNonJson(true) {
requiresElevatedPrivileges(false);
@ -133,6 +134,9 @@ void VPackFeature::collectOptions(
options->addOption(
"--hex", "read hex-encoded input",
new BooleanParameter(&_hexInput));
options->addOption(
"--json", "treat input as JSON",
new BooleanParameter(&_jsonInput));
options->addOption(
"--print-non-json", "print non-JSON types",
new BooleanParameter(&_printNonJson));
@ -169,17 +173,32 @@ void VPackFeature::start() {
(_printNonJson ? VPackOptions::ConvertUnsupportedType : VPackOptions::FailOnUnsupportedType);
options.customTypeHandler = &customTypeHandler;
try {
VPackValidator validator(&options);
validator.validate(s.c_str(), s.size(), false);
} catch (std::exception const& ex) {
std::cerr << "Invalid VPack input while processing infile '" << _inputFile
<< "': " << ex.what() << std::endl;
*_result = TRI_ERROR_INTERNAL;
return;
}
VPackSlice slice;
std::shared_ptr<VPackBuilder> builder;
VPackSlice const slice(s.c_str());
if (_jsonInput) {
try {
builder = VPackParser::fromJson(s);
slice = builder->slice();
} catch (std::exception const& ex) {
std::cerr << "Invalid JSON input while processing infile '" << _inputFile
<< "': " << ex.what() << std::endl;
*_result = TRI_ERROR_INTERNAL;
return;
}
} else {
try {
VPackValidator validator(&options);
validator.validate(s.c_str(), s.size(), false);
} catch (std::exception const& ex) {
std::cerr << "Invalid VPack input while processing infile '" << _inputFile
<< "': " << ex.what() << std::endl;
*_result = TRI_ERROR_INTERNAL;
return;
}
slice = VPackSlice(s.data());
}
VPackBuffer<char> buffer(4096);
VPackCharBufferSink sink(&buffer);
@ -220,10 +239,10 @@ void VPackFeature::start() {
// cppcheck-suppress *
if (!toStdOut) {
std::cout << "Successfully converted JSON infile '" << _inputFile << "'"
std::cout << "Successfully processed infile '" << _inputFile << "'"
<< std::endl;
std::cout << "VPack Infile size: " << s.size() << std::endl;
std::cout << "JSON Outfile size: " << buffer.size() << std::endl;
std::cout << "Infile size: " << s.size() << std::endl;
std::cout << "Outfile size: " << buffer.size() << std::endl;
}
*_result = TRI_ERROR_NO_ERROR;

View File

@ -44,6 +44,7 @@ class VPackFeature final
std::string _inputFile;
std::string _outputFile;
bool _prettyPrint;
bool _jsonInput;
bool _hexInput;
bool _printNonJson;
};

View File

@ -50,7 +50,8 @@ int main(int argc, char* argv[]) {
int ret;
server.addFeature(new ConfigFeature(&server, "arangovpack"));
// default is to use no config file
server.addFeature(new ConfigFeature(&server, "arangovpack", "none"));
server.addFeature(new LoggerFeature(&server, false));
server.addFeature(new RandomFeature(&server));
server.addFeature(new ShellColorsFeature(&server));

View File

@ -41,9 +41,10 @@ using namespace arangodb::rest;
using namespace arangodb::options;
ConfigFeature::ConfigFeature(application_features::ApplicationServer* server,
std::string const& progname)
std::string const& progname,
std::string const& configFilename)
: ApplicationFeature(server, "Config"),
_file(""),
_file(configFilename),
_checkConfiguration(false),
_progname(progname) {
setOptional(false);

View File

@ -29,7 +29,8 @@ namespace arangodb {
class ConfigFeature final : public application_features::ApplicationFeature {
public:
ConfigFeature(application_features::ApplicationServer* server,
std::string const& progname);
std::string const& progname,
std::string const& configFilename = "");
public:
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;

View File

@ -130,7 +130,7 @@ static void throwFileReadError(std::string const& filename) {
strerror(res));
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << message;
THROW_ARANGO_EXCEPTION(TRI_ERROR_SYS_ERROR);
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_SYS_ERROR, message);
}
static void fillStringBuffer(int fd, std::string const& filename,