From 627107d640c95f6f748b85247a2f0d56f8c11121 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 16 Feb 2018 13:52:10 +0100 Subject: [PATCH] cli: accept string values for secret flags I find very annoying to have to remember the numeric value of secret flags or have to look them up in the manual every time. Accept the textual version as well and add support for auto-completion. $ nmcli con modify c 802-11-wireless-security.psk-flags not-required $ nmcli con modify c 802-11-wireless-security.psk-flags agent-owned none not-required not-saved --- clients/common/nm-meta-setting-desc.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 6a238be0ad..52d5f1e390 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -1175,20 +1175,24 @@ _set_fcn_gobject_mac (ARGS_SET_FCN) static gboolean _set_fcn_gobject_secret_flags (ARGS_SET_FCN) { - gs_free const char **strv = NULL; - const char **iter; - unsigned long flags = 0, val_int; + gs_free char *err_token = NULL; + gs_free char *str_all = NULL; + int flags; nm_assert (!error || !*error); - strv = nm_utils_strsplit_set (value, " \t,"); - for (iter = strv; iter && *iter; iter++) { - if (!nmc_string_to_uint (*iter, TRUE, 0, ALL_SECRET_FLAGS, &val_int)) { - g_set_error (error, 1, 0, _("'%s' is not a valid flag number; use <0-%d>"), - *iter, ALL_SECRET_FLAGS); - return FALSE; - } - flags += val_int; + if (!nm_utils_enum_from_str (nm_setting_secret_flags_get_type (), + value, + &flags, + &err_token)) { + str_all = nm_utils_enum_to_str (nm_setting_secret_flags_get_type (), + ALL_SECRET_FLAGS); + g_set_error (error, 1, 0, + _("'%s' is not a valid flag; use <0-%d> or a combination of '%s'"), + err_token, + ALL_SECRET_FLAGS, + str_all); + return FALSE; } /* Validate the flags number */ @@ -4883,6 +4887,7 @@ static const NMMetaPropertyType _pt_gobject_mac = { static const NMMetaPropertyType _pt_gobject_secret_flags = { .get_fcn = _get_fcn_gobject_secret_flags, .set_fcn = _set_fcn_gobject_secret_flags, + .values_fcn = _values_fcn_gobject_enum, }; static const NMMetaPropertyType _pt_gobject_enum = {