aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/actions.c b/src/actions.c
index 74b6338..501d952 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -23,12 +23,12 @@ ERRLOG(action);
int run_INIT(UserOpt * opt, Conf *conf) {
UNUSED(conf);
if (db_exists(opt)) {
- printf("Current configuration file location: %s\n", opt->confDir);
- PRINT_ERR("ck is already initialized.");
- return 1;
+ ERR("ck is already initialized in %s", opt->confDir);
+ return -1;
}
if (init_create_config_file(opt)) {
- return 1;
+ HELP("Cound not create config file.");
+ return -2;
}
DB db = init_make_DB(opt);
if (db.error == SQL_NO_ERR) {
@@ -42,7 +42,7 @@ int run_ADD(UserOpt * opt, Conf *conf) {
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {
- PRINT_ERR("The database file is currupted. Run ck init anew.");
+ ERR("The database file is currupted. Run ck init anew.");
}
goto error;
}
@@ -78,7 +78,7 @@ int run_DEL(UserOpt * opt, Conf *conf) {
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {
- PRINT_ERR("The database file is currupted. Run ck init anew.");
+ ERR("The database file is currupted. Run ck init anew.");
}
goto error;
}
@@ -104,7 +104,7 @@ int run_EDIT(UserOpt *opt, Conf *conf) {
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {
- PRINT_ERR("The database file is currupted. Run ck init anew.");
+ ERR("The database file is currupted. Run ck init anew.");
}
return 1;
}
@@ -167,7 +167,7 @@ int run_LIST(UserOpt *opt, Conf *conf) {
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {
- printf("no tables\n");
+ ERR("The database file is currupted. Run ck init anew.");
}
return 1;
}
@@ -176,6 +176,7 @@ int run_LIST(UserOpt *opt, Conf *conf) {
ListOpt listOpt = list_make_options(opt->args);
if (listOpt.err) {
+ ERR("Wrong list options.");
goto error;
}
char tmp[STR_L] = "";
@@ -211,8 +212,6 @@ int run_LIST(UserOpt *opt, Conf *conf) {
}
get_program_paths(&db, the_list, listOpt.pName, 0, listOpt.attr);
break;
- case LT_NONE:
- goto error;
}
switch(listOpt._lst) {
case LST_PLAIN:
@@ -269,6 +268,16 @@ int run_SEARCH(UserOpt *opt, Conf *conf) {
}
int run_HELP(UserOpt *opt, Conf *conf) {
- printf("Running %s\n", "help");
+ UNUSED(conf);
+ switch(parser_get_action(list_get(opt->args), NULL)) {
+#define X(ACTION) \
+ case CKA_##ACTION: \
+ print_##ACTION##_help(); \
+ return 0;
+ CK_ACTIONS
+#undef X
+ default:
+ ERR("Unknown action: %s", list_get(opt->args));
+ }
return 1;
}