10 constexpr
int OPT_HELP = 1000;
11 constexpr
int OPT_RAW = 1001;
12 constexpr
int OPT_STDIN = 1002;
13 constexpr
int OPT_STDOUT = 1003;
15 constexpr option OPTIONS[] = {
16 {
"algorithm", required_argument,
nullptr,
'a'},
17 {
"decompress", no_argument,
nullptr,
'd'},
18 {
"force", no_argument,
nullptr,
'f'},
19 {
"generator", required_argument,
nullptr,
'g'},
20 {
"help", no_argument,
nullptr, OPT_HELP},
21 {
"list", no_argument,
nullptr,
'l'},
22 {
"output", required_argument,
nullptr,
'o'},
23 {
"stats", optional_argument,
nullptr,
's'},
24 {
"version", no_argument,
nullptr,
'v'},
25 {
"raw", no_argument,
nullptr, OPT_RAW},
26 {
"usestdin", no_argument,
nullptr, OPT_STDIN},
27 {
"usestdout", no_argument,
nullptr, OPT_STDOUT},
28 {
"logdir", required_argument,
nullptr,
'L'},
29 {
"loglevel", required_argument,
nullptr,
'O'},
30 {
"logverbosity", required_argument,
nullptr,
'V'},
36 static inline void print_usage(
const std::string& cmd, std::ostream& out) {
41 out << setw(7) <<
"Usage: " << cmd <<
" [OPTION] " 42 << setw(11) <<
"FILE" <<
"(1)" << endl;
43 out << setw(7) <<
"or: " << cmd <<
" [OPTION] " 44 << setw(11) <<
"--usestdin" <<
"(2)" << endl;
45 out << setw(7) <<
"or: " << cmd <<
" [OPTION] " 46 << setw(11) <<
"-g GENERATOR" <<
"(3)" << endl;
50 out <<
"Compresses or decompresses a file (1), an input received via stdin (2) or a" << endl;
51 out <<
"generated string (3). Depending on the selected input, an output (either a" << endl;
52 out <<
"file or stdout) may need to be specified." << endl;
56 out <<
"Options:" << endl;
58 constexpr
int W_SF = 4;
59 constexpr
int W_NOSF = 6;
60 constexpr
int W_LF = 24;
61 constexpr
int W_INDENT = 30;
64 out << right << setw(W_SF) <<
"-a" <<
", " 65 << left << setw(W_LF) <<
"--algorithm=ALGORITHM" 66 <<
"use ALGORITHM for (de-)compression" 67 << endl << setw(W_INDENT) <<
"" <<
"(use -l for more information)" 71 out << right << setw(W_SF) <<
"-d" <<
", " 72 << left << setw(W_LF) <<
"--decompress" 73 <<
"decompress the input (instead of compressing it)" 77 out << right << setw(W_SF) <<
"-f" <<
", " 78 << left << setw(W_LF) <<
"--force" 79 <<
"overwrite output file if it exists" 83 out << right << setw(W_SF) <<
"-g" <<
", " 84 << left << setw(W_LF) <<
"--generator=GENERATOR" 85 <<
"generate the input using GENERATOR" 86 << endl << setw(W_INDENT) <<
"" <<
"(use -l for more information)" 90 out << right << setw(W_SF) <<
"-l" <<
", " 91 << left << setw(W_LF) <<
"--list" 92 <<
"list available (de-)compression algorithms" 96 out << right << setw(W_SF) <<
"-o" <<
", " 97 << left << setw(W_LF) <<
"--output=FILE" 98 <<
"write output to FILE." 102 out << right << setw(W_SF) <<
"-s" <<
", " 103 << left << setw(W_LF) <<
"--stats[=TITLE]" 104 <<
"print (de-)compression statistics in JSON format" 108 out << right << setw(W_NOSF) <<
"" 109 << left << setw(W_LF) <<
"--help" 110 <<
"display this help" 114 out << right << setw(W_NOSF) <<
"" 115 << left << setw(W_LF) <<
"--raw" 116 <<
"(de-)compress without writing/reading a header" 120 out << right << setw(W_NOSF) <<
"" 121 << left << setw(W_LF) <<
"--usestdin" 122 <<
"use stdin for input" 126 out << right << setw(W_NOSF) <<
"" 127 << left << setw(W_LF) <<
"--usestdout" 128 <<
"use stdout for input" 132 out << right << setw(W_SF) <<
"-v" <<
", " 133 << left << setw(W_LF) <<
"--version" 134 <<
"print the version number of this build" 138 out << right << setw(W_SF) <<
"-L" <<
", " 139 << left << setw(W_LF) <<
"--logdir=path" 140 <<
"instead of logging to stdout use a log dir" 141 << endl << setw(W_INDENT) <<
"" <<
"in which log files are saved" 145 out << right << setw(W_SF) <<
"-O" <<
", " 146 << left << setw(W_LF) <<
"--loglevel=[0|1|2|3]" 147 <<
"log messages at or above this level" 148 << endl << setw(W_INDENT) <<
"" <<
"levels are INFO, WARNING, ERROR, and FATAL, " 149 << endl << setw(W_INDENT) <<
"" <<
"enumerated by 0, 1, 2, and 3, respectively." 153 out << right << setw(W_SF) <<
"-V" <<
", " 154 << left << setw(W_LF) <<
"--logverbosity=[0|1|2]" 155 <<
"show all VLOG(m) messages for m less or equal the value of this flag" 161 bool m_unknown_options;
167 std::string m_algorithm;
169 std::string m_output;
171 bool m_stdin, m_stdout;
172 std::string m_generator;
178 std::string m_stats_title;
180 std::vector<std::string> m_remaining;
185 Options(
const Options& other) =
delete;
186 Options(Options&& other) =
delete;
188 inline Options(
int argc,
char **argv) :
189 m_unknown_options(false),
200 int c, option_index = 0;
201 while((c = getopt_long(argc, argv,
"O:V:L:a:dfg:lo:s::v",
202 OPTIONS, &option_index)) != -1) {
206 m_algorithm = std::string(optarg);
218 m_generator = std::string(optarg);
231 m_output = std::string(optarg);
236 if(optarg) m_stats_title = std::string(optarg);
241 FLAGS_log_dir = std::string(optarg);
242 FLAGS_logtostderr = 0;
245 FLAGS_v = std::stoi(std::string(optarg));
248 FLAGS_minloglevel = std::stoi(std::string(optarg));
268 m_unknown_options =
true;
272 std::cerr <<
"Unhandled option \"" <<
273 OPTIONS[option_index].name <<
"\"";
279 while(optind < argc) {
280 m_remaining.emplace_back(argv[optind++]);
285 const bool& unknown_options = m_unknown_options;
287 const bool& help = m_help;
288 const bool& version = m_version;
289 const bool& list = m_list;
291 const std::string& algorithm = m_algorithm;
293 const std::string& output = m_output;
294 const bool& force = m_force;
295 const bool& stdin = m_stdin;
296 const bool& stdout = m_stdout;
297 const std::string& generator = m_generator;
299 const bool& raw = m_raw;
300 const bool& decompress = m_decompress;
302 const bool& stats = m_stats;
303 const std::string& stats_title = m_stats_title;
305 const std::vector<std::string>& remaining = m_remaining;