Commit ac07cbb9 authored by Thomas Haller's avatar Thomas Haller

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.
parent 8f037a11
......@@ -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");
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment