aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-11-13 13:22:53 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-11-13 13:22:53 +0200
commit6a43f7bfdfdb693e877943490abd5839a630ad9d (patch)
tree35c48a0acf80e6288aef952f93caac3195ba55ec /src/actions.c
parentd015a5e66ac9b92bba4eb5020e7bf2384f65ed25 (diff)
downloadck-6a43f7bfdfdb693e877943490abd5839a630ad9d.tar.gz
ck-6a43f7bfdfdb693e877943490abd5839a630ad9d.tar.bz2
ck-6a43f7bfdfdb693e877943490abd5839a630ad9d.zip
Fixed homedir with restore and updated delete
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/actions.c b/src/actions.c
index 990b371..5a3befe 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -74,27 +74,38 @@ int run_ADD(UserOpt * opt, Conf *conf) {
int run_DEL(UserOpt * opt, Conf *conf) {
UNUSED(conf);
DB db;
+ db = open_DB(opt);
+ if (db.ptr == NULL) {
+ if (db.error == SQL_ERR_NO_TABLES) {
+ ERR("The database file is currupted. Run ck init anew.");
+ }
+ return -1;
+ }
- DelOpt delOpt = del_make_options(opt->args);
- switch(delOpt.err) {
- case DEL_NO_ERR:
- db = open_DB(opt);
- if (db.ptr == NULL) {
- if (db.error == SQL_ERR_NO_TABLES) {
- ERR("The database file is currupted. Run ck init anew.");
- }
- return -1;
+ int rc = -1;
+ /* Since we are here, args have to be 1 or 2 */
+ char *pName = list_get(opt->args);
+ if (!program_exists(&db, pName)) {
+ ERR("Program %s doesn't exist in the database.", pName);
+ goto error;
+ }
+
+ /* If there is no next argument */
+ if (!list_next(opt->args)) {
+ rc = del_transaction_try(&db, pName, NULL);
+ }
+ /* If there are more arguments */
+ else {
+ char *cName = list_get(opt->args);
+ 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);
}
- int rc = del_transaction_try(&db, delOpt.arg, delOpt.isConf);
- close_DB(&db);
- return rc;
- case DEL_ERR_WRONG_ARGS:
- ERR("Wrong delete arguments.");
- break;
- case DEL_ERR_WRONG_PATH:
- ERR("Path %s doesnt exist.", delOpt.arg);
}
- return -1;
+ error:
+ close_DB(&db);
+ return rc;
}
int run_EDIT(UserOpt *opt, Conf *conf) {
@@ -309,7 +320,6 @@ int run_HELP(UserOpt *opt, Conf *conf) {
}
int run_RESTORE(UserOpt *opt, Conf *conf) {
- UNUSED(conf);
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {