From 431b75824b29e50f2ee80b6b0c8e56c0dc769572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 6 Feb 2014 11:12:18 +0100 Subject: cli: set vs. append property value by 'nmcli con modify' (rh #1044027) Previously 'nmcli con modify' appended values for multi-value properties. This commit makes 'nmcli con modify' overwrite the whole value. You can choose appending values by prefixing the setting.property with '+' sign. For simple (not container) properties the behaviour is the same both with and without the '+', of course. Synopsis: nmcli connection modify [+]. Example: ---> ipv4.dns = 1.2.3.4 $ nmcli connection modify my-em1 ipv4.dns 8.8.8.8 ---> ipv4.dns = 8.8.8.8 $ nmcli connection modify my-em1 +ipv4.dns 8.8.4.4 ---> ipv4.dns = 8.8.8.8 8.8.4.4 https://bugzilla.redhat.com/show_bug.cgi?id=1044027 --- cli/src/connections.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cli/src/connections.c b/cli/src/connections.c index 49c5dc85c0..d204fab4b9 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -268,7 +268,7 @@ usage (void) #endif " down [id | uuid | path | apath] \n\n" " add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n" - " modify [--temporary] [id | uuid | path] . \n\n" + " modify [--temporary] [id | uuid | path] [+]. \n\n" " edit [id | uuid | path] \n" " edit [type ] [con-name ]\n\n" " delete [id | uuid | path] \n\n" @@ -416,10 +416,13 @@ usage_connection_modify (void) fprintf (stderr, _("Usage: nmcli connection modify { ARGUMENTS | help }\n" "\n" - "ARGUMENTS := [id | uuid | path] . []\n" + "ARGUMENTS := [id | uuid | path] [+]. \n" "\n" "Modify a single property in the connection profile.\n" - "The profile is identified by its name, UUID or D-Bus path.\n\n")); + "The profile is identified by its name, UUID or D-Bus path.\n\n" + "\n" + "Examples:\n" + "nmcli con mod em1-1 +ipv4.dns 8.8.4.4\n\n")); } static void @@ -7825,7 +7828,10 @@ modify_connection_cb (NMRemoteConnection *connection, } static NMCResultCode -do_connection_modify (NmCli *nmc, gboolean temporary, int argc, char **argv) +do_connection_modify (NmCli *nmc, + gboolean temporary, + int argc, + char **argv) { NMConnection *connection = NULL; NMRemoteConnection *rc = NULL; @@ -7839,6 +7845,7 @@ do_connection_modify (NmCli *nmc, gboolean temporary, int argc, char **argv) char **strv = NULL; const char *setting_name; char *property_name = NULL; + gboolean append = FALSE; GError *error = NULL; nmc->should_wait = FALSE; @@ -7894,6 +7901,12 @@ do_connection_modify (NmCli *nmc, gboolean temporary, int argc, char **argv) nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; goto finish; } + + if (set_prop[0] == '+') { + set_prop++; + append = TRUE; + } + strv = g_strsplit (set_prop, ".", 2); if (g_strv_length (strv) != 2) { g_string_printf (nmc->return_text, _("Error: invalid . '%s'."), @@ -7937,6 +7950,8 @@ do_connection_modify (NmCli *nmc, gboolean temporary, int argc, char **argv) nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; goto finish; } + if (!append) + nmc_setting_reset_property (setting, property_name, NULL); if (!nmc_setting_set_property (setting, property_name, value, &error)) { g_string_printf (nmc->return_text, _("Error: failed to modify %s.%s: %s."), strv[0], strv[1], error->message); -- cgit v1.2.1