diff options
-rw-r--r-- | cli/mmcli-bearer.c | 11 | ||||
-rw-r--r-- | cli/mmcli-common.c | 44 | ||||
-rw-r--r-- | cli/mmcli-common.h | 4 | ||||
-rw-r--r-- | cli/mmcli-modem.c | 13 | ||||
-rw-r--r-- | cli/mmcli.c | 3 |
5 files changed, 59 insertions, 16 deletions
diff --git a/cli/mmcli-bearer.c b/cli/mmcli-bearer.c index b3bb85e1..5fe50fab 100644 --- a/cli/mmcli-bearer.c +++ b/cli/mmcli-bearer.c @@ -43,17 +43,12 @@ typedef struct { static Context *ctx; /* Options */ -static gchar *bearer_str; static gboolean info_flag; /* set when no action found */ static gchar *connect_with_number_str; static gboolean connect_flag; static gboolean disconnect_flag; static GOptionEntry entries[] = { - { "bearer", 'b', 0, G_OPTION_ARG_STRING, &bearer_str, - "Specify bearer by path. Shows bearer information if no action specified.", - NULL - }, { "connect", 'c', 0, G_OPTION_ARG_NONE, &connect_flag, "Connect a given bearer using the default number, if any.", NULL @@ -94,7 +89,7 @@ mmcli_bearer_options_enabled (void) connect_flag + disconnect_flag); - if (n_actions == 0 && bearer_str) { + if (n_actions == 0 && mmcli_get_common_bearer_string ()) { /* default to info */ info_flag = TRUE; n_actions++; @@ -330,7 +325,7 @@ mmcli_bearer_run_asynchronous (GDBusConnection *connection, /* Get proper bearer */ mmcli_get_bearer (connection, - bearer_str, + mmcli_get_common_bearer_string (), cancellable, (GAsyncReadyCallback)get_bearer_ready, NULL); @@ -344,7 +339,7 @@ mmcli_bearer_run_synchronous (GDBusConnection *connection) /* Initialize context */ ctx = g_new0 (Context, 1); ctx->bearer = mmcli_get_bearer_sync (connection, - bearer_str, + mmcli_get_common_bearer_string (), &ctx->manager, &ctx->object); diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c index 0bb80473..bf44a108 100644 --- a/cli/mmcli-common.c +++ b/cli/mmcli-common.c @@ -549,3 +549,47 @@ mmcli_get_lock_string (MMModemLock lock) value = g_enum_get_value (enum_class, lock); return value->value_nick; } + +/* Common options */ +static gchar *modem_str; +static gchar *bearer_str; + +static GOptionEntry entries[] = { + { "modem", 'm', 0, G_OPTION_ARG_STRING, &modem_str, + "Specify modem by path or index. Shows modem information if no action specified.", + "[PATH|INDEX]" + }, + { "bearer", 'b', 0, G_OPTION_ARG_STRING, &bearer_str, + "Specify bearer by path. Shows bearer information if no action specified.", + "[PATH]" + }, + { NULL } +}; + +GOptionGroup * +mmcli_get_common_option_group (void) +{ + GOptionGroup *group; + + /* Status options */ + group = g_option_group_new ("common", + "Common options", + "Show common options", + NULL, + NULL); + g_option_group_add_entries (group, entries); + + return group; +} + +const gchar * +mmcli_get_common_modem_string (void) +{ + return modem_str; +} + +const gchar * +mmcli_get_common_bearer_string (void) +{ + return bearer_str; +} diff --git a/cli/mmcli-common.h b/cli/mmcli-common.h index a18b5076..1b682c73 100644 --- a/cli/mmcli-common.h +++ b/cli/mmcli-common.h @@ -56,4 +56,8 @@ const gchar *mmcli_get_state_string (MMModemState state); const gchar *mmcli_get_state_reason_string (MMModemStateChangeReason reason); const gchar *mmcli_get_lock_string (MMModemLock lock); +GOptionGroup *mmcli_get_common_option_group (void); +const gchar *mmcli_get_common_modem_string (void); +const gchar *mmcli_get_common_bearer_string (void); + #endif /* _MMCLI_COMMON_H_ */ diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 2e5c74de..8974f10f 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -43,7 +43,6 @@ typedef struct { static Context *ctx; /* Options */ -static gchar *modem_str; static gboolean info_flag; /* set when no action found */ static gboolean monitor_state_flag; static gboolean enable_flag; @@ -55,10 +54,6 @@ static gchar *create_bearer_str; static gchar *delete_bearer_str; static GOptionEntry entries[] = { - { "modem", 'm', 0, G_OPTION_ARG_STRING, &modem_str, - "Specify modem by path or index. Shows modem information if no action specified.", - NULL - }, { "monitor-state", 'w', 0, G_OPTION_ARG_NONE, &monitor_state_flag, "Monitor state of a given modem", NULL @@ -124,7 +119,7 @@ mmcli_modem_options_enabled (void) !!delete_bearer_str + !!factory_reset_str); - if (n_actions == 0 && modem_str) { + if (n_actions == 0 && mmcli_get_common_modem_string ()) { /* default to info */ info_flag = TRUE; n_actions++; @@ -759,7 +754,7 @@ mmcli_modem_run_asynchronous (GDBusConnection *connection, /* Get proper modem */ mmcli_get_modem (connection, - modem_str, + mmcli_get_common_modem_string (), cancellable, (GAsyncReadyCallback)get_modem_ready, NULL); @@ -775,7 +770,9 @@ mmcli_modem_run_synchronous (GDBusConnection *connection) /* Initialize context */ ctx = g_new0 (Context, 1); - ctx->object = mmcli_get_modem_sync (connection, modem_str, &ctx->manager); + ctx->object = mmcli_get_modem_sync (connection, + mmcli_get_common_modem_string (), + &ctx->manager); ctx->modem = mm_object_get_modem (ctx->object); /* Request to get info from modem? */ diff --git a/cli/mmcli.c b/cli/mmcli.c index a91f7cfe..a7c9072a 100644 --- a/cli/mmcli.c +++ b/cli/mmcli.c @@ -32,6 +32,7 @@ #include <libmm-glib.h> #include "mmcli.h" +#include "mmcli-common.h" #define PROGRAM_NAME "mmcli" #define PROGRAM_VERSION PACKAGE_VERSION @@ -177,6 +178,8 @@ main (gint argc, gchar **argv) context = g_option_context_new ("- Control and monitor the ModemManager"); g_option_context_add_group (context, mmcli_manager_get_option_group ()); + g_option_context_add_group (context, + mmcli_get_common_option_group ()); g_option_context_add_group (context, mmcli_modem_get_option_group ()); g_option_context_add_group (context, |