summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-05-02 10:47:20 +0200
committerThomas Haller <thaller@redhat.com>2018-07-25 17:08:37 +0200
commitac07cbb98bd6db6d79d1578a3a97d50cf454dd68 (patch)
treee16f3e0c6cd43be0409ac2ab5b5327b709c3845d
parent8f037a11f4d566526ab53b43a4d048eed06cc6f2 (diff)
downloadNetworkManager-ac07cbb98bd6db6d79d1578a3a97d50cf454dd68.tar.gz
cli: minor cleanup explicitly checking print_output
The print-output knows three modes: NORMAL, PRETTY, TERSE. Never compare whether a mode is != a particular mode. Instead, always explicitly check for the modes for which we enable a particular behavior. The effect is, that we always do something when the mode is set to a particular value. We don't ever do something, if the mode is not set to a particular value. Consistently opt-in is easier to understand.
-rw-r--r--clients/cli/connections.c6
-rw-r--r--clients/cli/devices.c4
-rw-r--r--clients/cli/nmcli.h2
-rw-r--r--clients/cli/utils.c4
4 files changed, 10 insertions, 6 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 9e6859dad4..dd5ac874a3 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -1283,7 +1283,9 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc)
int section_idx = g_array_index (print_settings_array, int, i);
const char *prop_name = (const char *) g_ptr_array_index (prop_array, i);
- if (nmc->nmc_config.print_output != NMC_PRINT_TERSE && !nmc->nmc_config.multiline_output && was_output)
+ if ( NM_IN_SET (nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
+ && !nmc->nmc_config.multiline_output
+ && was_output)
g_print ("\n"); /* Empty line */
was_output = FALSE;
@@ -1365,7 +1367,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
int group_idx = g_array_index (print_groups, int, i);
char *group_fld = (char *) g_ptr_array_index (group_fields, i);
- if ( nmc->nmc_config.print_output != NMC_PRINT_TERSE
+ if ( NM_IN_SET (nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
&& !nmc->nmc_config.multiline_output
&& was_output)
g_print ("\n");
diff --git a/clients/cli/devices.c b/clients/cli/devices.c
index a2535406a3..3145a5ed45 100644
--- a/clients/cli/devices.c
+++ b/clients/cli/devices.c
@@ -1465,7 +1465,9 @@ show_device_info (NMDevice *device, NmCli *nmc)
int section_idx = g_array_index (sections_array, int, k);
char *section_fld = (char *) g_ptr_array_index (fields_in_section, k);
- if (nmc->nmc_config.print_output != NMC_PRINT_TERSE && !nmc->nmc_config.multiline_output && was_output)
+ if ( NM_IN_SET (nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
+ && !nmc->nmc_config.multiline_output
+ && was_output)
g_print ("\n"); /* Print empty line between groups in tabular mode */
was_output = FALSE;
diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h
index d817e09b2b..2861685563 100644
--- a/clients/cli/nmcli.h
+++ b/clients/cli/nmcli.h
@@ -75,7 +75,7 @@ typedef enum {
static inline NMMetaAccessorGetType
nmc_print_output_to_accessor_get_type (NMCPrintOutput print_output)
{
- return (print_output != NMC_PRINT_TERSE)
+ return NM_IN_SET (print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
? NM_META_ACCESSOR_GET_TYPE_PRETTY
: NM_META_ACCESSOR_GET_TYPE_PARSABLE;
}
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index 35b6f16812..9b7b4c4b33 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -1093,7 +1093,7 @@ _print_fill (const NmcConfig *nmc_config,
NULL));
if (cell->text_format == PRINT_DATA_CELL_FORMAT_TYPE_PLAIN) {
- if ( nmc_config->print_output != NMC_PRINT_TERSE
+ if ( NM_IN_SET (nmc_config->print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
&& ( !cell->text.plain
|| !cell->text.plain[0])) {
_print_data_cell_clear_text (cell);
@@ -1219,7 +1219,7 @@ _print_do (const NmcConfig *nmc_config,
: NULL;
/* print the header for the tabular form */
- if ( nmc_config->print_output != NMC_PRINT_TERSE
+ if ( NM_IN_SET (nmc_config->print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
&& !multiline) {
for (i_col = 0; i_col < col_len; i_col++) {
const PrintDataHeaderCell *header_cell = &header_row[i_col];