aboutsummaryrefslogtreecommitdiffstats
path: root/src/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.c')
-rw-r--r--src/init.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/init.c b/src/init.c
index e38a6f5..5f47b33 100644
--- a/src/init.c
+++ b/src/init.c
@@ -1,11 +1,19 @@
-#include "actions.h"
+/* init.c - the init action --------------------------------------------*- C -*-
+ *
+ * This file is part of ck, the config keeper
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Copyright (C) 2018 Anastasis Grammenos
+ * GPLv3 (see LICENCE for the full notice)
+ *
+ * -------------------------------------------------------------------------- */
#include "dblayer.h"
-#include "queries.h"
#include "ckerrlog.h"
ERRLOG(init);
-int init_create_config_file(UserOpt *opt) {
+static int init_create_config_file(UserOpt *opt) {
char absVCdir[STR_L] = "";
if (!util_file_exists(list_get_at(opt->args, 0), absVCdir)) {
ERR("Version control directory: %s does not exist.", list_get_at(opt->args, 0));
@@ -49,7 +57,7 @@ int init_create_config_file(UserOpt *opt) {
return 0;
}
-void init_make_tables(DB *db) {
+static void init_make_tables(DB *db) {
char sql[STR_L] = "";
dbh_form_query_make_tables(sql);
@@ -60,3 +68,27 @@ void init_make_tables(DB *db) {
return;
}
}
+
+int run_INIT(UserOpt * opt, Conf *conf) {
+ UNUSED(conf);
+ if (db_exists(opt)) {
+ ERR("ck is already initialized in %s", opt->confDir);
+ return -1;
+ }
+ if (init_create_config_file(opt)) {
+ sERR("Cound not create config file.");
+ return -1;
+ }
+ DB db;
+ if (open_DB(&db, opt)) {
+ return -1;
+ }
+ init_make_tables(&db);
+ sqlite3_close(db.ptr);
+ hLOG("Initialized empty ckdb.");
+ return 0;
+}
+
+void print_INIT_help() {
+ HELP("ck init VERSION_CONTROL_DIR SECRET_DIR");
+}