summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-08-08 20:43:22 +0200
committerThomas Haller <thaller@redhat.com>2018-08-10 10:38:19 +0200
commit9e7b33558b76dd006dbfe5aaa6856cfe8feac5d7 (patch)
tree97cd241f372789d228d39a2bb61f4b059d3c0a5a
parentcb058a49e69c7ad2479e74676bba8e3f776b3599 (diff)
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).
-rw-r--r--clients/cli/utils.c13
-rw-r--r--clients/common/nm-meta-setting-desc.h5
2 files changed, 17 insertions, 1 deletions
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index ea2c7de86..8cbfe9f2f 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -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)) {
diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h
index acb0a223b..31f1dd51b 100644
--- a/clients/common/nm-meta-setting-desc.h
+++ b/clients/common/nm-meta-setting-desc.h
@@ -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 {