summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-05-02 10:47:20 +0200
committerThomas Haller <thaller@redhat.com>2018-06-13 15:29:41 +0200
commit17c8792cf6e2279930c8a2d583301d081c4e3b4b (patch)
tree545ff63d7f6fe211b39ae6b5d84df3d8d9495dce
parent10b98bfee9b17844db5806add6f140875d1792bc (diff)
downloadNetworkManager-17c8792cf6e2279930c8a2d583301d081c4e3b4b.tar.gz
cli: minor cleanup evaluating print_output
The print-output knows three modes: NORMAL, PRETTY, TERSE. Instead of using local variables "pretty" and "terse", check for the output mode directly. Note how we have tree modes, so mapping them to two boolean variables is confusing. Especially at one place where we did: pretty = (nmc_config->print_output != NMC_PRINT_TERSE); while at other places: pretty = (nmc_config->print_output == NMC_PRINT_PRETTY);
-rw-r--r--clients/cli/utils.c60
1 files changed, 39 insertions, 21 deletions
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index 987917c245..e2cf253dfb 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -959,11 +959,9 @@ _print_fill (const NmcConfig *nmc_config,
GArray *header_row;
guint i_row, i_col;
guint targets_len;
- gboolean pretty;
NMMetaAccessorGetType text_get_type;
NMMetaAccessorGetFlags text_get_flags;
- pretty = (nmc_config->print_output != NMC_PRINT_TERSE);
header_row = g_array_sized_new (FALSE, TRUE, sizeof (PrintDataHeaderCell), cols_len);
g_array_set_clear_func (header_row, _print_data_header_cell_clear);
@@ -1077,7 +1075,9 @@ _print_fill (const NmcConfig *nmc_config,
NULL));
if (cell->text_format == PRINT_DATA_CELL_FORMAT_TYPE_PLAIN) {
- if (pretty && (!cell->text.plain|| !cell->text.plain[0])) {
+ if ( nmc_config->print_output != NMC_PRINT_TERSE
+ && ( !cell->text.plain
+ || !cell->text.plain[0])) {
_print_data_cell_clear_text (cell);
cell->text.plain = "--";
} else if (!cell->text.plain)
@@ -1165,8 +1165,6 @@ _print_do (const NmcConfig *nmc_config,
{
int width1, width2;
int table_width = 0;
- gboolean pretty = (nmc_config->print_output == NMC_PRINT_PRETTY);
- gboolean terse = (nmc_config->print_output == NMC_PRINT_TERSE);
gboolean multiline = nmc_config->multiline_output;
guint i_row, i_col;
nm_auto_free_gstring GString *str = NULL;
@@ -1174,7 +1172,8 @@ _print_do (const NmcConfig *nmc_config,
g_assert (col_len);
/* Main header */
- if (pretty && header_name_no_l10n) {
+ if ( nmc_config->print_output == NMC_PRINT_PRETTY
+ && header_name_no_l10n) {
gs_free char *line = NULL;
int header_width;
const char *header_name = _(header_name_no_l10n);
@@ -1201,7 +1200,8 @@ _print_do (const NmcConfig *nmc_config,
: NULL;
/* print the header for the tabular form */
- if (!multiline && !terse) {
+ if ( nmc_config->print_output != NMC_PRINT_TERSE
+ && !multiline) {
for (i_col = 0; i_col < col_len; i_col++) {
const PrintDataHeaderCell *header_cell = &header_row[i_col];
const char *title;
@@ -1224,7 +1224,7 @@ _print_do (const NmcConfig *nmc_config,
g_string_truncate (str, 0);
/* Print horizontal separator */
- if (pretty) {
+ if (nmc_config->print_output == NMC_PRINT_PRETTY) {
gs_free char *line = NULL;
g_print ("%s\n", (line = g_strnfill (table_width, '-')));
@@ -1269,10 +1269,15 @@ _print_do (const NmcConfig *nmc_config,
prefix = g_strdup_printf ("%s:", cell->header_cell->title);
width1 = strlen (prefix);
width2 = nmc_string_screen_width (prefix, NULL);
- g_print ("%-*s%s\n", (int) (terse ? 0 : ML_VALUE_INDENT+width1-width2), prefix, text);
+ g_print ("%-*s%s\n",
+ (int) ( nmc_config->print_output == NMC_PRINT_TERSE
+ ? 0
+ : ML_VALUE_INDENT+width1-width2),
+ prefix,
+ text);
} else {
nm_assert (str);
- if (terse) {
+ if (nmc_config->print_output == NMC_PRINT_TERSE) {
if (nmc_config->escape_values) {
const char *p = text;
while (*p) {
@@ -1306,7 +1311,7 @@ _print_do (const NmcConfig *nmc_config,
g_string_truncate (str, 0);
}
- if ( pretty
+ if ( nmc_config->print_output == NMC_PRINT_PRETTY
&& multiline) {
gs_free char *line = NULL;
@@ -1516,8 +1521,6 @@ print_required_fields (const NmcConfig *nmc_config,
int table_width = 0;
const char *not_set_str;
int i;
- gboolean terse = (nmc_config->print_output == NMC_PRINT_TERSE);
- gboolean pretty = (nmc_config->print_output == NMC_PRINT_PRETTY);
gboolean main_header_add = of_flags & NMC_OF_FLAG_MAIN_HEADER_ADD;
gboolean main_header_only = of_flags & NMC_OF_FLAG_MAIN_HEADER_ONLY;
gboolean field_names = of_flags & NMC_OF_FLAG_FIELD_NAMES;
@@ -1527,7 +1530,9 @@ print_required_fields (const NmcConfig *nmc_config,
nmc_terminal_spawn_pager (nmc_config);
/* --- Main header --- */
- if ((main_header_add || main_header_only) && pretty) {
+ if ( nmc_config->print_output == NMC_PRINT_PRETTY
+ && ( main_header_add
+ || main_header_only)) {
gs_free char *line = NULL;
int header_width;
@@ -1552,11 +1557,13 @@ print_required_fields (const NmcConfig *nmc_config,
return;
/* No field headers are printed in terse mode nor for multiline output */
- if ((terse || nmc_config->multiline_output) && field_names)
+ if ( ( nmc_config->print_output == NMC_PRINT_TERSE
+ || nmc_config->multiline_output)
+ && field_names)
return;
/* Don't replace empty strings in terse mode */
- not_set_str = terse ? "" : "--";
+ not_set_str = nmc_config->print_output == NMC_PRINT_TERSE ? "" : "--";
if (nmc_config->multiline_output) {
for (i = 0; i < indices->len; i++) {
@@ -1589,7 +1596,12 @@ print_required_fields (const NmcConfig *nmc_config,
j);
width1 = strlen (tmp);
width2 = nmc_string_screen_width (tmp, NULL);
- g_print ("%-*s%s\n", (int) (terse ? 0 : ML_VALUE_INDENT+width1-width2), tmp, print_val);
+ g_print ("%-*s%s\n",
+ (int) (nmc_config->print_output == NMC_PRINT_TERSE
+ ? 0
+ : ML_VALUE_INDENT + width1 - width2),
+ tmp,
+ print_val);
}
} else {
gs_free char *val_to_free = NULL;
@@ -1609,10 +1621,15 @@ print_required_fields (const NmcConfig *nmc_config,
nm_meta_abstract_info_get_name (field_values[idx].info, FALSE));
width1 = strlen (tmp);
width2 = nmc_string_screen_width (tmp, NULL);
- g_print ("%-*s%s\n", (int) (terse ? 0 : ML_VALUE_INDENT+width1-width2), tmp, print_val);
+ g_print ("%-*s%s\n",
+ (int) ( nmc_config->print_output == NMC_PRINT_TERSE
+ ? 0
+ : ML_VALUE_INDENT + width1 - width2),
+ tmp,
+ print_val);
}
}
- if (pretty) {
+ if (nmc_config->print_output == NMC_PRINT_PRETTY) {
gs_free char *line = NULL;
g_print ("%s\n", (line = g_strnfill (ML_HEADER_WIDTH, '-')));
@@ -1635,7 +1652,7 @@ print_required_fields (const NmcConfig *nmc_config,
value = get_value_to_print (nmc_config, (NmcOutputField *) field_values+idx, field_names,
not_set_str, &val_to_free);
- if (terse) {
+ if (nmc_config->print_output == NMC_PRINT_TERSE) {
if (nmc_config->escape_values) {
const char *p = value;
while (*p) {
@@ -1669,7 +1686,8 @@ print_required_fields (const NmcConfig *nmc_config,
g_print ("%s\n", str->str);
/* Print horizontal separator */
- if (field_names && pretty) {
+ if ( nmc_config->print_output == NMC_PRINT_PRETTY
+ && field_names) {
gs_free char *line = NULL;
g_print ("%s\n", (line = g_strnfill (table_width, '-')));