Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2,213 changes: 2,213 additions & 0 deletions .uncrustifyrc

Large diffs are not rendered by default.

85 changes: 32 additions & 53 deletions bin/autoconfig/CCmdLineParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@

#include <iostream>

namespace ml
{
namespace autoconfig
{
namespace ml {
namespace autoconfig {

const std::string CCmdLineParser::DESCRIPTION =
"Usage: autoconfig [options]\n"
"Options";
"Usage: autoconfig [options]\n"
"Options";

bool CCmdLineParser::parse(int argc,
const char * const *argv,
Expand All @@ -44,108 +42,89 @@ bool CCmdLineParser::parse(int argc,
std::string &outputFileName,
bool &isOutputFileNamedPipe,
bool &verbose,
bool &writeDetectorConfigs)
{
try
{
bool &writeDetectorConfigs) {
try {
boost::program_options::options_description desc(DESCRIPTION);
desc.add_options()
("help", "Display this information and exit")
("version", "Display version information and exit")
("logProperties", boost::program_options::value<std::string>(),
"Optional logger properties file")
"Optional logger properties file")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are much better than clang, which will need formatting disabling for option lists I think.

("logPipe", boost::program_options::value<std::string>(),
"Optional log to named pipe")
"Optional log to named pipe")
("delimiter", boost::program_options::value<char>(),
"Optional delimiter character for delimited data formats - default is ',' (comma separated)")
"Optional delimiter character for delimited data formats - default is ',' (comma separated)")
("lengthEncodedInput",
"Take input in length encoded binary format - default is delimited")
"Take input in length encoded binary format - default is delimited")
("timefield", boost::program_options::value<std::string>(),
"Optional name of the field containing the timestamp - default is 'time'")
"Optional name of the field containing the timestamp - default is 'time'")
("timeformat", boost::program_options::value<std::string>(),
"Optional format of the date in the time field in strptime code - default is the epoch time in seconds")
"Optional format of the date in the time field in strptime code - default is the epoch time in seconds")
("config", boost::program_options::value<std::string>(),
"Optional configuration file")
"Optional configuration file")
("input", boost::program_options::value<std::string>(),
"Optional file to read input from - not present means read from STDIN")
"Optional file to read input from - not present means read from STDIN")
("inputIsPipe", "Specified input file is a named pipe")
("output", boost::program_options::value<std::string>(),
"Optional file to write output to - not present means write to STDOUT")
"Optional file to write output to - not present means write to STDOUT")
("outputIsPipe", "Specified output file is a named pipe")
("verbose", "Output information about all detectors including those that have been discarded")
("writeDetectorConfigs",
"Output the detector configurations in JSON format")
"Output the detector configurations in JSON format")
;

boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);

if (vm.count("help") > 0)
{
if (vm.count("help") > 0) {
std::cerr << desc << std::endl;
return false;
}
if (vm.count("version") > 0)
{
if (vm.count("version") > 0) {
std::cerr << ver::CBuildInfo::fullInfo() << std::endl;
return false;
}
if (vm.count("logProperties") > 0)
{
if (vm.count("logProperties") > 0) {
logProperties = vm["logProperties"].as<std::string>();
}
if (vm.count("logPipe") > 0)
{
if (vm.count("logPipe") > 0) {
logPipe = vm["logPipe"].as<std::string>();
}
if (vm.count("delimiter") > 0)
{
if (vm.count("delimiter") > 0) {
delimiter = vm["delimiter"].as<char>();
}
if (vm.count("lengthEncodedInput") > 0)
{
if (vm.count("lengthEncodedInput") > 0) {
lengthEncodedInput = true;
}
if (vm.count("timefield") > 0)
{
if (vm.count("timefield") > 0) {
timeField = vm["timefield"].as<std::string>();
}
if (vm.count("timeformat") > 0)
{
if (vm.count("timeformat") > 0) {
timeFormat = vm["timeformat"].as<std::string>();
}
if (vm.count("config") > 0)
{
if (vm.count("config") > 0) {
configFile = vm["config"].as<std::string>();
}
if (vm.count("input") > 0)
{
if (vm.count("input") > 0) {
inputFileName = vm["input"].as<std::string>();
}
if (vm.count("inputIsPipe") > 0)
{
if (vm.count("inputIsPipe") > 0) {
isInputFileNamedPipe = true;
}
if (vm.count("output") > 0)
{
if (vm.count("output") > 0) {
outputFileName = vm["output"].as<std::string>();
}
if (vm.count("outputIsPipe") > 0)
{
if (vm.count("outputIsPipe") > 0) {
isOutputFileNamedPipe = true;
}
if (vm.count("verbose") > 0)
{
if (vm.count("verbose") > 0) {
verbose = true;
}
if (vm.count("writeDetectorConfigs") > 0)
{
if (vm.count("writeDetectorConfigs") > 0) {
writeDetectorConfigs = true;
}
}
catch (std::exception &e)
{
} catch (std::exception &e) {
std::cerr << "Error processing command line: " << e.what() << std::endl;
return false;
}
Expand Down
9 changes: 3 additions & 6 deletions bin/autoconfig/CCmdLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
#include <string>
#include <vector>

namespace ml
{
namespace autoconfig
{
namespace ml {
namespace autoconfig {

//! \brief Very simple command line parser.
//!
Expand All @@ -33,8 +31,7 @@ namespace autoconfig
//! IMPLEMENTATION DECISIONS:\n
//! Put in a class rather than main to allow testing.
//!
class CCmdLineParser
{
class CCmdLineParser {
public:
typedef std::vector<std::string> TStrVec;

Expand Down
34 changes: 13 additions & 21 deletions bin/autoconfig/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,21 @@
#include <stdlib.h>


int main(int argc, char **argv)
{
int main(int argc, char **argv) {
// Read command line options
std::string logProperties;
std::string logPipe;
char delimiter(',');
bool lengthEncodedInput(false);
char delimiter(',');
bool lengthEncodedInput(false);
std::string timeField("time");
std::string timeFormat;
std::string configFile;
std::string inputFileName;
bool isInputFileNamedPipe(false);
bool isInputFileNamedPipe(false);
std::string outputFileName;
bool isOutputFileNamedPipe(false);
bool verbose(false);
bool writeDetectorConfigs(false);
bool isOutputFileNamedPipe(false);
bool verbose(false);
bool writeDetectorConfigs(false);
if (ml::autoconfig::CCmdLineParser::parse(argc,
argv,
logProperties,
Expand All @@ -77,8 +76,7 @@ int main(int argc, char **argv)
outputFileName,
isOutputFileNamedPipe,
verbose,
writeDetectorConfigs) == false)
{
writeDetectorConfigs) == false) {
return EXIT_FAILURE;
}

Expand All @@ -89,8 +87,7 @@ int main(int argc, char **argv)
outputFileName,
isOutputFileNamedPipe);

if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false)
{
if (ml::core::CLogger::instance().reconfigure(logPipe, logProperties) == false) {
LOG_FATAL("Could not reconfigure logging");
return EXIT_FAILURE;
}
Expand All @@ -102,20 +99,16 @@ int main(int argc, char **argv)

ml::core::CProcessPriority::reducePriority();

if (ioMgr.initIo() == false)
{
if (ioMgr.initIo() == false) {
LOG_FATAL("Failed to initialise IO");
return EXIT_FAILURE;
}

typedef boost::scoped_ptr<ml::api::CInputParser> TScopedInputParserP;
TScopedInputParserP inputParser;
if (lengthEncodedInput)
{
if (lengthEncodedInput) {
inputParser.reset(new ml::api::CLengthEncodedInputParser(ioMgr.inputStream()));
}
else
{
} else {
inputParser.reset(new ml::api::CCsvInputParser(ioMgr.inputStream(), delimiter));
}

Expand All @@ -134,8 +127,7 @@ int main(int argc, char **argv)
0, // no persistence at present
*inputParser,
configurer);
if (skeleton.ioLoop() == false)
{
if (skeleton.ioLoop() == false) {
LOG_FATAL("Ml autoconfig failed");
return EXIT_FAILURE;
}
Expand Down
Loading