@@ -182,6 +182,11 @@ bool oscap_module_usage(struct oscap_module *module, FILE *out, const char *err,
182
182
return (out != stderr );
183
183
}
184
184
185
+ static const char * common_opts_help =
186
+ "Common options:\n"
187
+ " --verbose <verbosity_level> - Turn on verbose mode at specified verbosity level.\n"
188
+ " --verbose-log-file <file> - Write verbose informations into file.\n" ;
189
+
185
190
static void oscap_module_print_help (struct oscap_module * module , FILE * out )
186
191
{
187
192
assert (module != NULL );
@@ -196,7 +201,9 @@ static void oscap_module_print_help(struct oscap_module *module, FILE *out)
196
201
oscap_module_print_usage (module , out , true);
197
202
fprintf (out , "\n\n" );
198
203
199
- if (module -> help ) fprintf (out , "%s\n\n" , module -> help );
204
+ fprintf (out , "%s\n" , common_opts_help );
205
+ if (module -> help )
206
+ fprintf (out , "%s\n\n" , module -> help );
200
207
201
208
if (module -> submodules ) {
202
209
fprintf (out , "Commands:\n" );
@@ -231,28 +238,48 @@ enum oscap_common_opts {
231
238
OPT_LISTMODS ,
232
239
OPT_LISTALLMODS ,
233
240
OPT_MODTREE ,
234
- OPT_HELP = 'h'
241
+ OPT_HELP = 'h' ,
242
+ OPT_VERBOSE ,
243
+ OPT_VERBOSE_LOG_FILE
235
244
};
236
245
237
- static enum oscap_common_opts oscap_parse_common_opts (int argc , char * * argv )
246
+ static enum oscap_common_opts oscap_parse_common_opts (int argc , char * * argv , struct oscap_action * action )
238
247
{
239
248
static const struct option opts [] = {
240
249
{ "help" , 0 , 0 , OPT_HELP },
241
250
{ "list-submodules" , 0 , 0 , OPT_LISTMODS },
242
251
{ "list-all-submodules" , 0 , 0 , OPT_LISTALLMODS },
243
252
{ "module-tree" , 0 , 0 , OPT_MODTREE },
253
+ { "verbose" , required_argument , NULL , OPT_VERBOSE },
254
+ { "verbose-log-file" , required_argument , NULL , OPT_VERBOSE_LOG_FILE },
244
255
{ 0 , 0 , 0 , 0 }
245
256
};
246
257
247
- int optind_bak = optind ;
248
- int opterr_bak = opterr ;
249
- opterr = 0 ;
250
- int r = getopt_long (argc , argv , "+h" , opts , NULL );
251
- opterr = opterr_bak ;
252
- switch (r ) {
253
- case -1 : case '?' : optind = optind_bak ; return OPT_NONE ;
254
- default : return r ;
255
- }
258
+ int r ;
259
+ int optind_bak = optind ;
260
+ int opterr_bak = opterr ;
261
+ opterr = 0 ;
262
+ while ((r = getopt_long (argc , argv , "+h" , opts , NULL )) != -1 ) {
263
+ switch (r ) {
264
+ case OPT_VERBOSE :
265
+ optind_bak += 2 ;
266
+ action -> verbosity_level = optarg ;
267
+ break ;
268
+ case OPT_VERBOSE_LOG_FILE :
269
+ optind_bak += 2 ;
270
+ action -> f_verbose_log = optarg ;
271
+ break ;
272
+ case 0 :
273
+ break ;
274
+ case '?' :
275
+ optind = optind_bak ;
276
+ opterr = opterr_bak ;
277
+ return OPT_NONE ;
278
+ default :
279
+ return r ;
280
+ }
281
+ }
282
+ return OPT_NONE ;
256
283
}
257
284
258
285
int oscap_module_call (struct oscap_action * action )
@@ -328,7 +355,7 @@ int oscap_module_process(struct oscap_module *module, int argc, char **argv)
328
355
329
356
getopt_parse_env (module , & argc , & argv );
330
357
331
- switch (oscap_parse_common_opts (argc , argv )) {
358
+ switch (oscap_parse_common_opts (argc , argv , & action )) {
332
359
case OPT_HELP : oscap_module_print_help (module , stdout ); goto cleanup ;
333
360
case OPT_LISTMODS : oscap_print_submodules (module , stdout , "\n" , false); goto cleanup ;
334
361
case OPT_LISTALLMODS : oscap_print_submodules (module , stdout , "\n" , true); goto cleanup ;
@@ -345,6 +372,12 @@ int oscap_module_process(struct oscap_module *module, int argc, char **argv)
345
372
}
346
373
347
374
if (module -> func ) {
375
+ if (!check_verbose_options (& action )) {
376
+ goto cleanup ;
377
+ }
378
+ if (!oscap_set_verbose (action .verbosity_level , action .f_verbose_log , false)) {
379
+ goto cleanup ;
380
+ }
348
381
ret = oscap_module_call (& action );
349
382
goto cleanup ;
350
383
}
0 commit comments