From ac07cbb98bd6db6d79d1578a3a97d50cf454dd68 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 2 May 2018 10:47:20 +0200 Subject: [PATCH] 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. --- clients/cli/connections.c | 6 ++++-- clients/cli/devices.c | 4 +++- clients/cli/nmcli.h | 2 +- clients/cli/utils.c | 4 ++-- 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];