From 8be3fc37e304852d7f0ac956f689c96ac538c8de Mon Sep 17 00:00:00 2001
From: Pawel Szewczyk
Date: Tue, 7 Jul 2015 17:20:56 +0200
Subject: [PATCH] function: Add --quiet option to list-types command
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
---
source/function/include/function.h | 4 ++++
source/function/src/function.c | 32 ++++++++++++++++++++++++++------
source/function/src/function_gadgetd.c | 7 ++++++-
source/function/src/function_libusbg.c | 8 +++++++-
4 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/source/function/include/function.h b/source/function/include/function.h
index f0a21ed..aced5fc 100644
--- a/source/function/include/function.h
+++ b/source/function/include/function.h
@@ -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;
diff --git a/source/function/src/function.c b/source/function/src/function.c
index 1e9c4a7..84964fd 100644
--- a/source/function/src/function.c
+++ b/source/function/src/function.c
@@ -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);
}
diff --git a/source/function/src/function_gadgetd.c b/source/function/src/function_gadgetd.c
index 0617399..d46c1f8 100644
--- a/source/function/src/function_gadgetd.c
+++ b/source/function/src/function_gadgetd.c
@@ -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);
diff --git a/source/function/src/function_libusbg.c b/source/function/src/function_libusbg.c
index d9df233..71fd9a2 100644
--- a/source/function/src/function_libusbg.c
+++ b/source/function/src/function_libusbg.c
@@ -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));
--
2.7.4