From 21c92f735ff52ff98b50f7f9d8e8ab9c46dad557 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 17 Nov 2018 19:49:52 +0200 Subject: Finish restructure and simplify include graph --- src/init.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/init.c') 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"); +} -- cgit v1.2.3