nmcli: always print "--" for empty or unset values in normal/pretty output

This was already true for tabular ouput mode.
Align to this behavior when printing in multiline mode.
This commit is contained in:
Francesco Giudici 2017-01-17 11:58:40 +01:00
parent 39f1d44ec8
commit 6520cf1171
2 changed files with 14 additions and 8 deletions

View file

@ -2503,10 +2503,13 @@ nmc_property_connection_get_permissions (NMSetting *setting, NmcPropertyGetType
if (nm_setting_connection_get_permission (s_con, i, &perm_type, &perm_item, NULL))
g_string_append_printf (perm, "%s:%s,", perm_type, perm_item);
}
if (perm->len > 0)
if (perm->len > 0) {
g_string_truncate (perm, perm->len-1); /* remove trailing , */
return g_string_free (perm, FALSE);
}
return g_string_free (perm, FALSE);
/* No value from get_permission */
return g_string_free (perm, TRUE);
}
DEFINE_GETTER (nmc_property_connection_get_zone, NM_SETTING_CONNECTION_ZONE)

View file

@ -1026,10 +1026,13 @@ get_value_to_print (NmCli *nmc,
if (field_name)
value = _(field->name_l10n);
else
value = field->value ?
(is_array ? g_strjoinv (" | ", (char **) field->value) :
(char *) field->value) :
(char *) not_set_str;
value = field->value
? (is_array
? g_strjoinv (" | ", (char **) field->value)
: (*((char *) field->value)
? (char *) field->value
: (char *) not_set_str))
: (char *) not_set_str;
free_value = field->value && is_array && !field_name;
/* colorize the value */
@ -1143,7 +1146,7 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
const char *val = (const char*) field_values[idx].value;
char *print_val;
val = val ? val : not_set_str;
val = val && *val ? val : not_set_str;
print_val = colorize_string (nmc, field_values[idx].color, field_values[idx].color_fmt,
val, &free_print_val);
tmp = g_strdup_printf ("%s%s%s:",
@ -1192,7 +1195,7 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
} else {
width1 = strlen (value);
width2 = nmc_string_screen_width (value, NULL); /* Width of the string (in screen colums) */
g_string_append_printf (str, "%-*s", field_values[idx].width + width1 - width2, strlen (value) > 0 ? value : "--");
g_string_append_printf (str, "%-*s", field_values[idx].width + width1 - width2, strlen (value) > 0 ? value : not_set_str);
g_string_append_c (str, ' '); /* Column separator */
table_width += field_values[idx].width + width1 - width2 + 1;
}