15 Options::Options(
int argc,
char* argv[] ) {
17 CLI::App app(
"Compute statistics on an rdb table" );
21 app.add_option(
"-i,--input", input,
"Input RDB file" )->check(CLI::ExistingFile);
23 app.add_option(
"-o,--output", output,
"Output RDB file" );
25 auto opt_all = app.add_flag(
"-a,--all", all,
"Generate statistics for all numerical columns" );
26 auto opt_columns = app.add_option(
"columns", columns,
"specific columns to process" );
27 opt_all->excludes(opt_columns);
29 auto opt_group = app.add_option(
"-g,--group,-b,--break", group,
"group data by the specified columns" );
30 auto opt_rows = app.add_option(
"-r,--rows", rows,
"ranges of rows to operate on" );
32 opt_group->excludes( opt_rows );
34 auto normalize_map = std::map<std::string,Normalize>( {
35 {
"ave", Normalize::Average },
36 {
"med", Normalize::Median },
37 {
"none", Normalize::None }
40 app.add_option(
"-n,--normalize", normalize,
"Normalize the output statistics" )
41 ->transform( CLI::Transformer( normalize_map ));
43 app.add_option(
"-p,--percentiles", percentiles,
"Generate percentile statistics" );
45 app.add_flag(
"-q,--quartiles", quartiles,
"Generate quartile statistics" );
47 app.add_option(
"-d,--defn",
override,
"override column definition" );
49 app.add_flag(
"--manual,--usage", manual,
"output detailed help, then exit" );
51 app.parse( argc, argv );
55 exit_requested =
true;
56 exit_value = EXIT_SUCCESS;
60 catch (
const CLI::ParseError &e ) {
61 exit_requested =
true;
62 exit_value = app.exit(e);
68 Options::print( std::ostream& os ) {
70 os <<
"columns: " << to_string( columns ) <<
"\n";
72 os <<
"all: " << ( all ?
"true" :
"false" ) <<
"\n";
74 os <<
"groups: " << to_string( group ) <<
"\n";
76 os <<
"input: " << ( input.empty() ?
"stdin" : input ) <<
"\n";
77 os <<
"output: " <<( output.empty() ?
"stdout" : output ) <<
"\n";
79 os <<
"normalize: " << to_string( normalize ) <<
"\n";
81 os <<
"override: " << to_string(
override ) <<
"\n";
82 os <<
"percentiles: " << percentiles <<
"\n";
83 os <<
"quartiles: " << (quartiles ?
"true" :
"false") <<
"\n";
84 os <<
"rows: " << to_string( rows ) <<
"\n";
87 std::ostream& operator << ( std::ostream& os, Options& a ) {
92 std::string to_string( Normalize normalize ) {
94 normalize == Normalize::Average ?
"average" 95 : normalize == Normalize::Median ?
"median" 96 : normalize == Normalize::None ?
"none"