From 54ae271dfc5f8405233ed320b2e9bd821ee8210f Mon Sep 17 00:00:00 2001 From: gramanas Date: Fri, 16 Nov 2018 14:43:19 +0200 Subject: Code restructure/simplification, restore regression test --- src/actions.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 12 deletions(-) (limited to 'src/actions.c') diff --git a/src/actions.c b/src/actions.c index 882fa30..c977aee 100644 --- a/src/actions.c +++ b/src/actions.c @@ -8,10 +8,7 @@ * GPLv3 (see LICENCE for the full notice) * * -------------------------------------------------------------------------- */ -#include "actions.h" -#include "actionhelper.h" #include "dblayer.h" -#include "ckutil.h" #include "cklist.h" #include "ckerrlog.h" @@ -28,10 +25,12 @@ int run_INIT(UserOpt * opt, Conf *conf) { return -1; } DB db; - if (!init_make_DB(&db, opt)) { - init_make_tables(&db); + if (open_DB(&db, opt)) { + return -1; } + init_make_tables(&db); sqlite3_close(db.ptr); + hLOG("Initialized empty ckdb."); return 0; } @@ -56,15 +55,14 @@ int run_ADD(UserOpt * opt, Conf *conf) { if (add_transaction_try(&db, &addOpt, conf->home_dir)) { goto error; } - add_make_link(&addOpt, conf); - char err[STR_M] = ""; - if (add_err_message(err)) { - PRINT_ERR(err); + if (add_make_link(&addOpt, conf)) { error: close_DB(&db); + sERR("Could not complete add transaction."); return -1; } close_DB(&db); + hLOG("ckdb updated succesfully."); return 0; } @@ -93,11 +91,16 @@ int run_DEL(UserOpt * opt, Conf *conf) { rc = del_transaction_try(&db, pName, cName); if (rc) { HELP("Program %s doesn't have a config named %s", pName, cName); - edit_print_suggested_configs(&db, pName); + print_suggested_configs(&db, pName); } } error: close_DB(&db); + if (!rc) { + hLOG("ckdb updated succesfully."); + } else { + sERR("Could not complete delete transaction."); + } return rc; } @@ -131,7 +134,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) { /* If the program has many configs */ else { HELP("Ambiguous config. Please type the config name after the program."); - edit_print_suggested_configs(&db, pName); + print_suggested_configs(&db, pName); goto error; } } @@ -141,7 +144,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) { char *cName = list_get(opt->args); if (edit_get_config(&db, pName, confName, cName, &secret)) { ERR("Program %s doesn't have a config named %s", pName, cName); - edit_print_suggested_configs(&db, pName); + print_suggested_configs(&db, pName); goto error; } } @@ -360,3 +363,54 @@ int run_RESTORE(UserOpt *opt, Conf *conf) { list_free(to); return rc; } + +/**************/ +/* PRINT HELP */ +/**************/ + +void print_INIT_help() { + HELP("ck init VERSION_CONTROL_DIR SECRET_DIR"); +} + +void print_ADD_help() { + HELP("ck add PROGRAM_NAME CONFIG_PATH [-p] [-s]"); +} + +void print_DEL_help() { + HELP("ck delete PROGRAM_NAME [CONFIG_BASENAME]"); +} + +void print_EDIT_help() { + HELP("ck edit PROGRAM_NAME [CONFIG_BASENAME]"); +} + +void print_LIST_help() { + ckhelp("ck list tree [-a] [-b]"); + ckhelp("ck list -p PROGRAM_NAME [-t list-type] [-a] [-b]"); + ckhelp("ck list programs [-t list-type] [-a] [-b]"); + ckhelp("ck list paths [-t list-type] [-a] [-b]"); + ckhelp("ck list ckconf"); + report_help(); +} + +void print_SEARCH_help() { + HELP("ck search SEARCH_TERM"); +} + +void print_HELP_help() { + HELP("ck help action"); +} + +void print_RESTORE_help() { + ckhelp("ck restore -p PROGRAM_NAME"); + ckhelp("ck restore all"); + report_help(); +} + +void print_conf_help(void) { + HELP("ck [-v|--verbose] [-c|--config DIR] action [...]"); +} + +void print_verbose_help(void) { + HELP("ck [-v|--verbose] [-c|--config DIR] action [...]"); +} -- cgit v1.2.3