diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-11-17 19:49:52 +0200 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-11-17 19:49:52 +0200 |
commit | 21c92f735ff52ff98b50f7f9d8e8ab9c46dad557 (patch) | |
tree | 3b244ec29c3b3ad96fc141461bff4d141a36227a /src/init.c | |
parent | 8eb4df24eb30353bea82268440396e50ed8b1bbc (diff) | |
download | ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.tar.gz ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.tar.bz2 ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.zip |
Finish restructure and simplify include graph
Diffstat (limited to 'src/init.c')
-rw-r--r-- | src/init.c | 40 |
1 files changed, 36 insertions, 4 deletions
@@ -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"); +} |