cli: editor 'change' command: output -> input format conversion (rh #998929)

The format of property values that nmcli prints is not the same (for some
properties) as the format nmcli editor accepts as input from user. The reasons
are that (a) output format is more descriptive and not much suitable to be
typed, (b) it comes in most cases from libnm-util.
'change' command displays current property value and allows users to edit it.
So we convert the output into input format, before presenting it to the user.

https://bugzilla.redhat.com/show_bug.cgi?id=998929
This commit is contained in:
Jiří Klimeš
2013-09-11 17:32:00 +02:00
parent 42b6c6eac0
commit 1f6e1fbc62
3 changed files with 380 additions and 62 deletions

View File

@@ -4321,6 +4321,7 @@ set_deftext (void)
&& edit_lib_symbols.rl_insert_text_func && edit_lib_symbols.rl_insert_text_func
&& edit_lib_symbols.rl_startup_hook_x) { && edit_lib_symbols.rl_startup_hook_x) {
edit_lib_symbols.rl_insert_text_func (pre_input_deftext); edit_lib_symbols.rl_insert_text_func (pre_input_deftext);
g_free (pre_input_deftext);
pre_input_deftext = NULL; pre_input_deftext = NULL;
*edit_lib_symbols.rl_startup_hook_x = NULL; *edit_lib_symbols.rl_startup_hook_x = NULL;
} }
@@ -5301,7 +5302,7 @@ property_edit_submenu (NmCli *nmc,
case NMC_EDITOR_SUB_CMD_CHANGE: case NMC_EDITOR_SUB_CMD_CHANGE:
*edit_lib_symbols.rl_startup_hook_x = set_deftext; *edit_lib_symbols.rl_startup_hook_x = set_deftext;
pre_input_deftext = nmc_setting_get_property (curr_setting, prop_name, NULL); pre_input_deftext = nmc_setting_get_property_out2in (curr_setting, prop_name, NULL);
tmp_prompt = g_strdup_printf (_("Edit '%s' value: "), prop_name); tmp_prompt = g_strdup_printf (_("Edit '%s' value: "), prop_name);
prop_val_user = readline_x (tmp_prompt); prop_val_user = readline_x (tmp_prompt);
@@ -5360,9 +5361,9 @@ property_edit_submenu (NmCli *nmc,
else else
printf (_("Unknown command argument: '%s'\n"), cmd_property_arg); printf (_("Unknown command argument: '%s'\n"), cmd_property_arg);
} else { } else {
printf ("%s: %s\n", char *prop_val = nmc_setting_get_property (curr_setting, prop_name, NULL);
prop_name, printf ("%s: %s\n", prop_name, prop_val);
nmc_setting_get_property (curr_setting, prop_name, NULL)); g_free (prop_val);
} }
break; break;

File diff suppressed because it is too large Load Diff

View File

@@ -62,6 +62,9 @@ const char *nmc_setting_get_property_allowed_values (NMSetting *setting, const c
char *nmc_setting_get_property (NMSetting *setting, char *nmc_setting_get_property (NMSetting *setting,
const char *prop, const char *prop,
GError **error); GError **error);
char *nmc_setting_get_property_out2in (NMSetting *setting,
const char *prop,
GError **error);
gboolean nmc_setting_set_property (NMSetting *setting, gboolean nmc_setting_set_property (NMSetting *setting,
const char *prop, const char *prop,
const char *val, const char *val,