Blob Blame Raw
From cd698516de709ee3d8480fd7990a8082dffddb45 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Wed, 8 Jul 2015 17:04:41 +0200
Subject: [PATCH] cli: use internal command impl in the command process

It did not seem to be a good idea to add wrappers for the internal
commands, because the wrappers would be one line functions. Now, we need
to do more sophisticated processing (authenticate, chown), so adding the
wrappers is the best choice to provide the same functionality in the
command process.

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 src/cli/builtin-cmd.h |  3 +++
 src/cli/list.c        |  8 ++++++-
 src/cli/process.c     | 16 ++++---------
 src/cli/report.c      | 65 +++++++++++++++++++++++++++------------------------
 src/cli/rm.c          |  7 +++++-
 5 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/src/cli/builtin-cmd.h b/src/cli/builtin-cmd.h
index bc80479..c6cd691 100644
--- a/src/cli/builtin-cmd.h
+++ b/src/cli/builtin-cmd.h
@@ -22,8 +22,11 @@
 
 extern int cmd_list(int argc, const char **argv);
 extern int cmd_remove(int argc, const char **argv);
+extern int _cmd_remove(const char **dirs_strv);
 extern int cmd_report(int argc, const char **argv);
+extern int _cmd_report(const char **dirs_strv, int remove);
 extern int cmd_info(int argc, const char **argv);
+extern int _cmd_info(problem_data_t *problem_data, int detailed, int text_size);
 extern int cmd_status(int argc, const char **argv);
 extern int cmd_process(int argc, const char **argv);
 
diff --git a/src/cli/list.c b/src/cli/list.c
index e8ec37b..68dda47 100644
--- a/src/cli/list.c
+++ b/src/cli/list.c
@@ -168,6 +168,12 @@ int cmd_list(int argc, const char **argv)
     return 0;
 }
 
+int _cmd_info(problem_data_t *problem_data, int detailed, int text_size)
+{
+    print_crash(problem_data, detailed, text_size);
+    return 0;
+}
+
 int cmd_info(int argc, const char **argv)
 {
     const char *program_usage_string = _(
@@ -205,7 +211,7 @@ int cmd_info(int argc, const char **argv)
             continue;
         }
 
-        print_crash(problem, opt_detailed, text_size);
+        _cmd_info(problem, opt_detailed, text_size);
         problem_data_free(problem);
         if (*argv)
             printf("\n");
diff --git a/src/cli/process.c b/src/cli/process.c
index 39462f9..401ef60 100644
--- a/src/cli/process.c
+++ b/src/cli/process.c
@@ -68,28 +68,22 @@ static int process_one_crash(problem_data_t *problem_data)
         if(strcmp(action, "rm") == 0 || strcmp(action, "remove") == 0 )
         {
             log(_("Deleting '%s'"), dir_name);
-            delete_dump_dir_possibly_using_abrtd(dir_name);
+            const char *dirs_strv[] = {dir_name, NULL};
+            _cmd_remove(dirs_strv);
 
             ret_val = ACT_REMOVE;
         }
         else if (not_reportable == NULL && (strcmp(action, "e") == 0 || strcmp(action, "report") == 0))
         {
             log(_("Reporting '%s'"), dir_name);
-            report_problem_in_dir(dir_name,
-                                     LIBREPORT_WAIT
-                                   | LIBREPORT_RUN_CLI);
+            const char *dirs_strv[] = {dir_name, NULL};
+            _cmd_report(dirs_strv, /*do not delete*/0);
 
             ret_val = ACT_REPORT;
         }
         else if (strcmp(action, "i") == 0 || strcmp(action, "info") == 0)
         {
-            char *desc = make_description(problem_data,
-                                    /*names_to_skip:*/ NULL,
-                                    /*max_text_size:*/ CD_TEXT_ATT_SIZE_BZ,
-                                    MAKEDESC_SHOW_FILES | MAKEDESC_SHOW_MULTILINE);
-
-            fputs(desc, stdout);
-            free(desc);
+            _cmd_info(problem_data, /*detailed*/1, CD_TEXT_ATT_SIZE_BZ);
 
             ret_val = ACT_INFO;
         }
diff --git a/src/cli/report.c b/src/cli/report.c
index 194f7c9..19b4c51 100644
--- a/src/cli/report.c
+++ b/src/cli/report.c
@@ -22,38 +22,12 @@
 #include "abrt-cli-core.h"
 #include "builtin-cmd.h"
 
-int cmd_report(int argc, const char **argv)
+int _cmd_report(const char **dirs_strv, int remove)
 {
-    const char *program_usage_string = _(
-        "& report [options] DIR..."
-    );
-
-    enum {
-        OPT_v = 1 << 0,
-        OPT_d = 1 << 1,
-    };
-
-    struct options program_options[] = {
-        OPT__VERBOSE(&g_verbose),
-        OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
-        OPT_END()
-    };
-
-    unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
-    argv += optind;
-
-    if (!argv[0])
-        show_usage_and_die(program_usage_string, program_options);
-
-    export_abrt_envvars(/*prog_prefix:*/ 0);
-
-    load_abrt_conf();
-    free_abrt_conf_data();
-
     int ret = 0;
-    while (*argv)
+    while (*dirs_strv)
     {
-        const char *dir_name = *argv++;
+        const char *dir_name = *dirs_strv++;
         char *const real_problem_id = hash2dirname_if_necessary(dir_name);
         if (real_problem_id == NULL)
         {
@@ -75,7 +49,7 @@ int cmd_report(int argc, const char **argv)
                                            | LIBREPORT_RUN_CLI);
 
         /* the problem was successfully reported and option is -d */
-        if((opts & OPT_d) && (status == 0 || status == EXIT_STOP_EVENT_RUN))
+        if(remove && (status == 0 || status == EXIT_STOP_EVENT_RUN))
         {
             log(_("Deleting '%s'"), real_problem_id);
             delete_dump_dir_possibly_using_abrtd(real_problem_id);
@@ -89,3 +63,34 @@ int cmd_report(int argc, const char **argv)
 
     return ret;
 }
+
+int cmd_report(int argc, const char **argv)
+{
+    const char *program_usage_string = _(
+        "& report [options] DIR..."
+    );
+
+    enum {
+        OPT_v = 1 << 0,
+        OPT_d = 1 << 1,
+    };
+
+    struct options program_options[] = {
+        OPT__VERBOSE(&g_verbose),
+        OPT_BOOL('d', "delete", NULL, _("Remove PROBLEM_DIR after reporting")),
+        OPT_END()
+    };
+
+    unsigned opts = parse_opts(argc, (char **)argv, program_options, program_usage_string);
+    argv += optind;
+
+    if (!argv[0])
+        show_usage_and_die(program_usage_string, program_options);
+
+    export_abrt_envvars(/*prog_prefix:*/ 0);
+
+    load_abrt_conf();
+    free_abrt_conf_data();
+
+    return _cmd_report(argv, opts & OPT_d);
+}
diff --git a/src/cli/rm.c b/src/cli/rm.c
index 37d50e2..95ae097 100644
--- a/src/cli/rm.c
+++ b/src/cli/rm.c
@@ -52,6 +52,11 @@ static int remove_using_abrtd_or_fs(const char **dirs_strv)
     return errs;
 }
 
+int _cmd_remove(const char **dirs_strv)
+{
+    return (g_cli_authenticate ? remove_using_dbus : remove_using_abrtd_or_fs)(dirs_strv);
+}
+
 int cmd_remove(int argc, const char **argv)
 {
     const char *program_usage_string = _(
@@ -69,5 +74,5 @@ int cmd_remove(int argc, const char **argv)
     if (!argv[0])
         show_usage_and_die(program_usage_string, program_options);
 
-    return (g_cli_authenticate ? remove_using_dbus : remove_using_abrtd_or_fs)(argv);
+    return _cmd_remove(argv);
 }
-- 
2.4.3