cli: Extract log argument parsing into cli_common
Move log argument parsing into `cli_common.c` as it's also useful for
other CLIs. Also add a NULL-check for the strdup() return value.
Change-Id: I9b1c9ae2e490edd3560b11b84fddd79e4d396e1d
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/72986
diff --git a/include/cli.h b/include/cli.h
index 4ef264d..aec1a46 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -18,6 +18,8 @@
#include "libflashprog.h"
enum {
+ OPTION_VERBOSE = 'V',
+ OPTION_LOGFILE = 'o',
OPTION_CHIP = 'c',
OPTION_PROGRAMMER = 'p',
OPTION_LAYOUT = 'l',
@@ -32,6 +34,12 @@
OPTION_PROGRESS,
};
+struct log_args {
+ enum flashprog_log_level screen_level;
+ enum flashprog_log_level logfile_level;
+ char *logfile;
+};
+
struct flash_args {
char *chip;
char *prog_name;
@@ -47,6 +55,7 @@
int cli_check_filename(const char *filename, const char *type);
+int cli_parse_log_args(struct log_args *, int opt, const char *optarg);
int cli_parse_flash_args(struct flash_args *, int opt, const char *optarg);
int cli_parse_layout_args(struct layout_args *, int opt, const char *optarg);
int cli_process_layout_args(struct flashprog_layout **, struct flashprog_flashctx *, const struct layout_args *);