mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-06 13:48:36 +02:00
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 <TAB> agent-owned none not-required not-saved
This commit is contained in:
parent
997cce7c90
commit
627107d640
1 changed files with 16 additions and 11 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue