function: Add --quiet option to list-types command
authorPawel Szewczyk <p.szewczyk@samsung.com>
Tue, 7 Jul 2015 15:20:56 +0000 (17:20 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 28 Jul 2015 16:06:53 +0000 (18:06 +0200)
To provide output useful for scripting --quiet option is introduced - it
does not produce unnecessary messages keeping output as simple as
possible.

Change-Id: I7652c1b5ad307502855d1ee14cf779afb2b206ff
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
source/function/include/function.h
source/function/src/function.c
source/function/src/function_gadgetd.c
source/function/src/function_libusbg.c

index f0a21ed..aced5fc 100644 (file)
@@ -90,6 +90,10 @@ struct gt_func_rm_data {
        int opts;
 };
 
+struct gt_func_list_types_data {
+       int opts;
+};
+
 struct gt_func_get_data {
        const char *gadget;
        const char *type;
index 1e9c4a7..84964fd 100644 (file)
@@ -141,7 +141,11 @@ out:
 static int gt_func_list_types_help(void *data)
 {
        printf("usage: %s func list-types\n"
-              "List available function types.\n",
+              "List available function types.\n"
+              "\n"
+              "Options:\n"
+              "  -q, --quiet\tPrint only list of types\n"
+              "  -h, --help\tPrintf this help\n",
                program_name);
        return 0;
 }
@@ -149,11 +153,27 @@ static int gt_func_list_types_help(void *data)
 static void gt_parse_func_list_types(const Command *cmd, int argc,
                char **argv, ExecutableCommand *exec, void * data)
 {
-       if (argc == 0)
-               executable_command_set(exec, GET_EXECUTABLE(list_types),
-                               NULL, NULL);
-       else
-               executable_command_set(exec, gt_func_list_types_help, NULL, NULL);
+       struct gt_func_list_types_data *dt = NULL;
+       int avaible_opts = GT_QUIET | GT_HELP;
+       int ind;
+
+       dt = zalloc(sizeof(*dt));
+       if (dt == NULL)
+               goto out;
+
+       ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
+       if (ind < 0 || dt->opts & GT_HELP)
+               goto out;
+
+       if (argc - ind != 0)
+               goto out;
+
+       executable_command_set(exec, GET_EXECUTABLE(list_types),
+                               (void *)dt, free);
+       return;
+
+out:
+       executable_command_set(exec, gt_func_list_types_help, NULL, NULL);
 
 }
 
index 0617399..d46c1f8 100644 (file)
@@ -85,6 +85,9 @@ static int list_types_func(void *data)
        GVariantIter *iter;
        GVariant *v;
        gchar *s;
+       struct gt_func_list_types_data *dt;
+
+       dt = (struct gt_func_list_types_data *)data;
 
        v = g_dbus_connection_call_sync(backend_ctx.gadgetd_conn,
                                        "org.usb.gadgetd",
@@ -103,7 +106,9 @@ static int list_types_func(void *data)
                return -1;
        }
 
-       printf("Discovered functions:\n");
+       if (!(dt->opts & GT_QUIET))
+               printf("Discovered functions:\n");
+
        g_variant_get(v, "(as)", &iter);
        while (g_variant_iter_loop(iter, "s", &s))
               printf("  %s\n", s);
index d9df233..71fd9a2 100644 (file)
@@ -65,7 +65,13 @@ static int create_func(void *data)
 static int list_types_func(void *data)
 {
        int i;
-       printf("Functions known by library:\n");
+       struct gt_func_list_types_data *dt;
+
+       dt = (struct gt_func_list_types_data *)data;
+
+       if (!(dt->opts & GT_QUIET))
+               printf("Functions known by library:\n");
+
        for (i = USBG_FUNCTION_TYPE_MIN; i < USBG_FUNCTION_TYPE_MAX; i++)
                printf("  %s\n", usbg_get_function_type_str(i));