cli: specify common options in a new group

Actions on modems from specific interfaces, like 3GPP, will also need the modem
to be specified.

The new 'Common' option group will handle all options to specify objects.
This commit is contained in:
Aleksander Morgado
2011-12-21 13:05:25 +01:00
parent 265a516f42
commit 16f2b7bdb8
5 changed files with 59 additions and 16 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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_ */

View File

@@ -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? */

View File

@@ -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,