cli: change function for allowed values to return array of strings

This commit is contained in:
Jiří Klimeš 2015-04-22 12:10:53 +02:00
parent 5e1a7ffb39
commit 188d6cbaf3
3 changed files with 28 additions and 39 deletions

View file

@ -7614,7 +7614,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
if (menu_ctx.level == 1) {
const char *prop_name;
char *prop_val_user = NULL;
const char *avals;
const char **avals;
GError *tmp_err = NULL;
prop_name = ask_check_property (cmd_arg,
@ -7624,9 +7624,12 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
break;
avals = nmc_setting_get_property_allowed_values (menu_ctx.curr_setting, prop_name);
if (avals)
g_print (_("Allowed values for '%s' property: %s\n"), prop_name, avals);
if (avals) {
char *avals_str = nmc_util_strv_for_display (avals, FALSE);
g_print (_("Allowed values for '%s' property: %s\n"),
prop_name, avals_str);
g_free (avals_str);
}
prop_val_user = nmc_readline (_("Enter '%s' value: "), prop_name);
/* Set property value */
@ -7678,10 +7681,13 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
/* Ask for value */
if (!cmd_arg_v) {
const char *avals = nmc_setting_get_property_allowed_values (ss, prop_name);
if (avals)
g_print (_("Allowed values for '%s' property: %s\n"), prop_name, avals);
const char **avals = nmc_setting_get_property_allowed_values (ss, prop_name);
if (avals) {
char *avals_str = nmc_util_strv_for_display (avals, FALSE);
g_print (_("Allowed values for '%s' property: %s\n"),
prop_name, avals_str);
g_free (avals_str);
}
cmd_arg_v = nmc_readline (_("Enter '%s' value: "), prop_name);
}

View file

@ -1627,12 +1627,12 @@ register_nmcli_value_transforms (void)
/* Main hash table storing function pointer for manipulating properties */
static GHashTable *nmc_properties = NULL;
typedef char * (*NmcPropertyGetFunc) (NMSetting *);
typedef gboolean (*NmcPropertySetFunc) (NMSetting *, const char *, const char *, GError **);
typedef gboolean (*NmcPropertyRemoveFunc) (NMSetting *, const char *, const char *, guint32, GError **);
typedef const char * (*NmcPropertyDescribeFunc) (NMSetting *, const char *);
typedef const char * (*NmcPropertyValuesFunc) (NMSetting *, const char *);
typedef char * (*NmcPropertyOut2InFunc) (const char *);
typedef char * (*NmcPropertyGetFunc) (NMSetting *);
typedef gboolean (*NmcPropertySetFunc) (NMSetting *, const char *, const char *, GError **);
typedef gboolean (*NmcPropertyRemoveFunc) (NMSetting *, const char *, const char *, guint32, GError **);
typedef const char * (*NmcPropertyDescribeFunc) (NMSetting *, const char *);
typedef const char ** (*NmcPropertyValuesFunc) (NMSetting *, const char *);
typedef char * (*NmcPropertyOut2InFunc) (const char *);
typedef struct {
NmcPropertyGetFunc get_func; /* func getting property values */
@ -2177,13 +2177,10 @@ check_and_set_string (NMSetting *setting,
}
#define DEFINE_ALLOWED_VAL_FUNC(def_func, valid_values) \
static const char * \
static const char ** \
def_func (NMSetting *setting, const char *prop) \
{ \
static char *values = NULL; \
if (G_UNLIKELY (values == NULL)) \
values = g_strjoinv (", ", (char **) valid_values); \
return values; \
return valid_values; \
}
/* --- generic property setter functions --- */
@ -3080,17 +3077,10 @@ nmc_property_bond_describe_options (NMSetting *setting, const char *prop)
return desc;
}
static const char *
static const char **
nmc_property_bond_allowed_options (NMSetting *setting, const char *prop)
{
const char **valid_options;
static char *allowed_vals = NULL;
if (G_UNLIKELY (allowed_vals == NULL)) {
valid_options = nm_setting_bond_get_valid_options (NM_SETTING_BOND (setting));
allowed_vals = g_strjoinv (", ", (char **) valid_options);
}
return allowed_vals;
return nm_setting_bond_get_valid_options (NM_SETTING_BOND (setting));
}
/* --- NM_SETTING_INFINIBAND_SETTING_NAME property setter functions --- */
@ -4191,17 +4181,10 @@ DEFINE_REMOVER_OPTION (nmc_property_wired_remove_option_s390_options,
NM_SETTING_WIRED,
nm_setting_wired_remove_s390_option)
static const char *
static const char **
nmc_property_wired_allowed_s390_options (NMSetting *setting, const char *prop)
{
const char **valid_options;
static char *allowed_vals = NULL;
if (G_UNLIKELY (allowed_vals == NULL)) {
valid_options = nm_setting_wired_get_valid_s390_options (NM_SETTING_WIRED (setting));
allowed_vals = g_strjoinv (", ", (char **) valid_options);
}
return allowed_vals;
return nm_setting_wired_get_valid_s390_options (NM_SETTING_WIRED (setting));
}
static const char *
@ -6647,7 +6630,7 @@ nmc_setting_get_valid_properties (NMSetting *setting)
/*
* Return allowed values for 'prop' as a string.
*/
const char *
const char **
nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop)
{

View file

@ -37,7 +37,7 @@ void nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMCo
char **nmc_setting_get_valid_properties (NMSetting *setting);
char *nmc_setting_get_property_desc (NMSetting *setting, const char *prop);
const char *nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop);
const char **nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop);
char *nmc_setting_get_property (NMSetting *setting,
const char *prop,
GError **error);