Skip to content

Commit 99a792b

Browse files
committed
fdsdump: add -h command line option
1 parent dc12592 commit 99a792b

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/tools/fdsdump/src/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ main(int argc, char *argv[])
3030
try {
3131
Options options {argc, argv};
3232

33+
if (options.get_help_flag()) {
34+
Options::print_usage();
35+
return EXIT_SUCCESS;
36+
}
3337

3438
switch (options.get_mode()) {
3539
case Options::Mode::list:
@@ -44,6 +48,12 @@ main(int argc, char *argv[])
4448
default:
4549
throw std::runtime_error("Invalid mode");
4650
}
51+
52+
} catch (const OptionsException &ex) {
53+
std::cerr << "ERROR: " << ex.what() << std::endl;
54+
Options::print_usage();
55+
return EXIT_FAILURE;
56+
4757
} catch (const std::exception &ex) {
4858
std::cerr << "ERROR: " << ex.what() << std::endl;
4959
return EXIT_FAILURE;

src/tools/fdsdump/src/options.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919

2020
namespace fdsdump {
2121

22+
void Options::print_usage()
23+
{
24+
std::cerr << "Usage: fdsdump [OPTIONS]\n";
25+
std::cerr << "\n";
26+
std::cerr << "Options:\n";
27+
std::cerr << " -h, --help Show this help message\n";
28+
std::cerr << " -r, --input FILE File or glob pattern of files to read\n";
29+
std::cerr << " -f, --filter EXPR Select only records matching filter expression (default = all records)\n";
30+
std::cerr << " -o, --output FMT Output format - TABLE, JSON, JSON-RAW\n";
31+
std::cerr << " -O, --order FIELDS Record fields and order direction to order by\n";
32+
std::cerr << " -c, --limit NUM Max number of output records (default = infinite)\n";
33+
std::cerr << " -A, --aggregation-keys FIELDS Fields making up the aggregation key (default = none)\n";
34+
std::cerr << " -S, --aggregation-values FIELDS Fields that will be aggregated (default = flows,packets,bytes)\n";
35+
std::cerr << " -I, --stats-mode Run in statistics mode\n";
36+
std::cerr << " --no-biflow-autoignore Turn off smart ignoring of empty biflow records\n";
37+
}
38+
2239
Options::Options()
2340
{
2441
reset();
@@ -33,6 +50,7 @@ Options::Options(int argc, char *argv[])
3350

3451
void Options::reset()
3552
{
53+
m_help_flag = false;
3654
m_mode = Mode::undefined;
3755

3856
m_input_files.clear();
@@ -60,6 +78,7 @@ void Options::reset()
6078
void Options::parse(int argc, char *argv[])
6179
{
6280
ArgParser parser;
81+
parser.add('h', "help", false);
6382
parser.add('r', "input", true);
6483
parser.add('F', "filter", true);
6584
parser.add('o', "output", true);
@@ -79,6 +98,10 @@ void Options::parse(int argc, char *argv[])
7998
throw OptionsException("Unknown argument " + unknown.arg);
8099
}
81100

101+
if (args.has('h')) {
102+
m_help_flag = true;
103+
}
104+
82105
if (args.has('r')) {
83106
for (const auto &arg : args.get_all('r')) {
84107
m_input_files.add_files(arg);

src/tools/fdsdump/src/options.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class Options {
4343
stats,
4444
};
4545

46+
/**
47+
* @brief Print the usage message
48+
*/
49+
static void print_usage();
50+
4651
/**
4752
* @brief Create options with default values.
4853
*/
@@ -60,6 +65,8 @@ class Options {
6065
*/
6166
void reset();
6267

68+
bool get_help_flag() const { return m_help_flag; };
69+
6370
const Mode &get_mode() const { return m_mode; };
6471

6572
/** @brief Get list of files to process. */
@@ -86,6 +93,8 @@ class Options {
8693
private:
8794
Mode m_mode;
8895

96+
bool m_help_flag;
97+
8998
FileList m_input_files;
9099
std::string m_input_filter;
91100

0 commit comments

Comments
 (0)