aboutsummaryrefslogtreecommitdiffstats
path: root/src/clparser.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/clparser.h')
-rw-r--r--src/clparser.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/clparser.h b/src/clparser.h
new file mode 100644
index 0000000..9b22b87
--- /dev/null
+++ b/src/clparser.h
@@ -0,0 +1,68 @@
+/* clparser.h - Command line parser for ck -----------------------------*- C -*-
+ *
+ * This file is part of ck, the config keeper
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Copyright (C) 2018 Anastasis Grammenos
+ * GPLv3 (see LICENCE for the full notice)
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * The code here and in clparser.c is responsible for parsing
+ * the user's input from the command line and return a struct
+ * of the user's options ready to be handled by the rest of the
+ * procedures.
+ *
+ * -------------------------------------------------------------------------- */
+#ifndef CLPARSER_H
+#define CLPARSER_H
+
+#include "cklist.h"
+
+#define CK_ACTIONS \
+ X(INIT) \
+ X(ADD) \
+ X(DEL) \
+ X(EDIT) \
+ X(LIST) \
+ X(SEARCH) \
+ X(RESTORE) \
+ X(HELP)
+
+enum ParseErrors {
+ PERR_NOERR = 0,
+#define X(ACTION) \
+ PERR_##ACTION##_WRONG,
+ CK_ACTIONS
+#undef X
+ PERR_UNKNOWN_ACTION,
+};
+typedef enum ParseErrors ParseError;
+
+enum CkActions {
+ CK_WRONG_ACTION,
+#define X(ACTION) \
+ CKA_##ACTION,
+ CK_ACTIONS
+#undef X
+};
+typedef enum CkActions CkAction;
+
+typedef struct UserOptions UserOpt;
+struct UserOptions {
+ ParseError err;
+ CkAction action;
+ char *confDir;
+ cklist *args;
+};
+
+
+/* Parse cli args, fill UserOpt struct
+ * and return the result enum */
+int parse_action(int argc, const char **argv, UserOpt *opt);
+CkAction parser_get_action(const char *name, char *actionName);
+char * get_possible_action_strings(char *dest, CkAction ckAction);
+void free_user_opt(UserOpt *opt);
+
+#endif // CLPARSER_H