cli: add functionality to hide properties from output

Historically, nmcli printed all fields during operations like
`nmcli connection show "$PROFILE"`. As we supported more and
more options, this resulted in a verbose output, of most properties
just being the default values.

To counter that, we added the '-overview' option. When given,
it would hide options that are set at their default. This option
was not the default, to preserve established behavior.

However, for new options, we can afford to hide them. Add a mechanism,
that property getters can mark their value to be hidden. At the moment,
there is no way to show these properties. However, we could add a
'-verbose' option, with the opposite meaning of '-overview'. Anyway,
that does not seem necessary at the moment.

Hiding properties from output is only acceptable for new properties
(otherwise we badly change behavior), and if the properties are set
at their default values (otherwise, we hide important information).
This commit is contained in:
Thomas Haller 2018-08-08 20:43:22 +02:00
parent 8c752076aa
commit 582ee91145
2 changed files with 17 additions and 1 deletions

View file

@ -1092,7 +1092,18 @@ _print_fill (const NmcConfig *nmc_config,
nm_assert (!to_free || value == to_free);
if (!nmc_config->overview || !is_default)
if ( is_default
&& ( nmc_config->overview
|| NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE))) {
/* don't mark the entry for display. This is to shorten the output in case
* the property is the default value. But we only do that, if the user
* opts in to this behavior (-overview), or of the property marks itself
* elegible to be hidden.
*
* In general, only new API shall mark itself eligible to be hidden.
* Long established properties cannot, because it would be a change
* in behavior. */
} else
header_cell->to_print = TRUE;
if (NM_FLAGS_HAS (text_out_flags, NM_META_ACCESSOR_GET_OUT_FLAGS_STRV)) {

View file

@ -148,6 +148,11 @@ typedef enum {
typedef enum {
NM_META_ACCESSOR_GET_OUT_FLAGS_NONE = 0,
NM_META_ACCESSOR_GET_OUT_FLAGS_STRV = (1LL << 0),
/* the property allows to be hidden, if and only if, it's value is set to the
* default. This should only be set by new properties, to preserve behavior
* of old properties, which were always printed. */
NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE = (1LL << 1),
} NMMetaAccessorGetOutFlags;
typedef enum {