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) { if (menu_ctx.level == 1) {
const char *prop_name; const char *prop_name;
char *prop_val_user = NULL; char *prop_val_user = NULL;
const char *avals; const char **avals;
GError *tmp_err = NULL; GError *tmp_err = NULL;
prop_name = ask_check_property (cmd_arg, prop_name = ask_check_property (cmd_arg,
@ -7624,9 +7624,12 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
break; break;
avals = nmc_setting_get_property_allowed_values (menu_ctx.curr_setting, prop_name); avals = nmc_setting_get_property_allowed_values (menu_ctx.curr_setting, prop_name);
if (avals) if (avals) {
g_print (_("Allowed values for '%s' property: %s\n"), prop_name, 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); prop_val_user = nmc_readline (_("Enter '%s' value: "), prop_name);
/* Set property value */ /* Set property value */
@ -7678,10 +7681,13 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
/* Ask for value */ /* Ask for value */
if (!cmd_arg_v) { if (!cmd_arg_v) {
const char *avals = nmc_setting_get_property_allowed_values (ss, prop_name); const char **avals = nmc_setting_get_property_allowed_values (ss, prop_name);
if (avals) if (avals) {
g_print (_("Allowed values for '%s' property: %s\n"), prop_name, 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); 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 */ /* Main hash table storing function pointer for manipulating properties */
static GHashTable *nmc_properties = NULL; static GHashTable *nmc_properties = NULL;
typedef char * (*NmcPropertyGetFunc) (NMSetting *); typedef char * (*NmcPropertyGetFunc) (NMSetting *);
typedef gboolean (*NmcPropertySetFunc) (NMSetting *, const char *, const char *, GError **); typedef gboolean (*NmcPropertySetFunc) (NMSetting *, const char *, const char *, GError **);
typedef gboolean (*NmcPropertyRemoveFunc) (NMSetting *, const char *, const char *, guint32, GError **); typedef gboolean (*NmcPropertyRemoveFunc) (NMSetting *, const char *, const char *, guint32, GError **);
typedef const char * (*NmcPropertyDescribeFunc) (NMSetting *, const char *); typedef const char * (*NmcPropertyDescribeFunc) (NMSetting *, const char *);
typedef const char * (*NmcPropertyValuesFunc) (NMSetting *, const char *); typedef const char ** (*NmcPropertyValuesFunc) (NMSetting *, const char *);
typedef char * (*NmcPropertyOut2InFunc) (const char *); typedef char * (*NmcPropertyOut2InFunc) (const char *);
typedef struct { typedef struct {
NmcPropertyGetFunc get_func; /* func getting property values */ 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) \ #define DEFINE_ALLOWED_VAL_FUNC(def_func, valid_values) \
static const char * \ static const char ** \
def_func (NMSetting *setting, const char *prop) \ def_func (NMSetting *setting, const char *prop) \
{ \ { \
static char *values = NULL; \ return valid_values; \
if (G_UNLIKELY (values == NULL)) \
values = g_strjoinv (", ", (char **) valid_values); \
return values; \
} }
/* --- generic property setter functions --- */ /* --- generic property setter functions --- */
@ -3080,17 +3077,10 @@ nmc_property_bond_describe_options (NMSetting *setting, const char *prop)
return desc; return desc;
} }
static const char * static const char **
nmc_property_bond_allowed_options (NMSetting *setting, const char *prop) nmc_property_bond_allowed_options (NMSetting *setting, const char *prop)
{ {
const char **valid_options; return nm_setting_bond_get_valid_options (NM_SETTING_BOND (setting));
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;
} }
/* --- NM_SETTING_INFINIBAND_SETTING_NAME property setter functions --- */ /* --- 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,
nm_setting_wired_remove_s390_option) nm_setting_wired_remove_s390_option)
static const char * static const char **
nmc_property_wired_allowed_s390_options (NMSetting *setting, const char *prop) nmc_property_wired_allowed_s390_options (NMSetting *setting, const char *prop)
{ {
const char **valid_options; return nm_setting_wired_get_valid_s390_options (NM_SETTING_WIRED (setting));
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;
} }
static const char * static const char *
@ -6647,7 +6630,7 @@ nmc_setting_get_valid_properties (NMSetting *setting)
/* /*
* Return allowed values for 'prop' as a string. * Return allowed values for 'prop' as a string.
*/ */
const char * const char **
nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop) 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_valid_properties (NMSetting *setting);
char *nmc_setting_get_property_desc (NMSetting *setting, const char *prop); 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, char *nmc_setting_get_property (NMSetting *setting,
const char *prop, const char *prop,
GError **error); GError **error);