cli: Extract flash argument parsing into cli_common
Move the parsing logic for `-c` and `-p` into the new function
cli_parse_flash_args(). This way it can be shared with other CLIs.
We start a new header file `cli.h` for common CLI functions.
Change-Id: If3f5eff0a2f56a1235038b19b3c1d6586536fd5d
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/72982
diff --git a/include/cli.h b/include/cli.h
new file mode 100644
index 0000000..aef0b8d
--- /dev/null
+++ b/include/cli.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of the flashprog project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef FLASHPROG_CLI_H
+#define FLASHPROG_CLI_H
+
+enum {
+ OPTION_CHIP = 'c',
+ OPTION_PROGRAMMER = 'p',
+};
+
+struct flash_args {
+ char *chip;
+ char *prog_name;
+ char *prog_args;
+};
+
+int cli_parse_flash_args(struct flash_args *, int opt, const char *optarg);
+
+#endif