mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 13:40:39 +01:00
cli: use enum NmcOfFlags instead of plain integer flags and pass to print_required_fields()
This commit is contained in:
parent
cecee19b2b
commit
f12106d83a
5 changed files with 22 additions and 18 deletions
|
|
@ -798,7 +798,7 @@ nmc_connection_profile_details (NMConnection *connection, NmCli *nmc, gboolean s
|
|||
nmc_fields_settings_names, FALSE, NULL, NULL);
|
||||
|
||||
nmc_fields_settings_names[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
|
||||
print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_settings_names);
|
||||
print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, &out.print_fields, nmc_fields_settings_names);
|
||||
}
|
||||
|
||||
/* Loop through the required settings and print them. */
|
||||
|
|
@ -1225,7 +1225,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
|
|||
nmc_fields_con_active_details_groups, FALSE, NULL, NULL);
|
||||
|
||||
nmc_fields_con_active_details_groups[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
|
||||
print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_con_active_details_groups);
|
||||
print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, &out.print_fields, nmc_fields_con_active_details_groups);
|
||||
}
|
||||
|
||||
/* Loop through the groups and print them. */
|
||||
|
|
|
|||
|
|
@ -1116,7 +1116,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
|
|||
nmc_fields_dev_show_general, FALSE, NULL, NULL);
|
||||
|
||||
nmc_fields_dev_show_general[0].flags = NMC_OF_FLAG_MAIN_HEADER_ONLY;
|
||||
print_required_fields (&nmc->nmc_config, &out.print_fields, nmc_fields_dev_show_general);
|
||||
print_required_fields (&nmc->nmc_config, NMC_OF_FLAG_MAIN_HEADER_ONLY, &out.print_fields, nmc_fields_dev_show_general);
|
||||
}
|
||||
|
||||
/* Loop through the required sections and print them. */
|
||||
|
|
|
|||
|
|
@ -98,11 +98,13 @@ typedef enum {
|
|||
} NMCPrintOutput;
|
||||
|
||||
/* === Output fields === */
|
||||
/* Flags for NmcOutputField */
|
||||
#define NMC_OF_FLAG_FIELD_NAMES 0x00000001 /* Print field names instead of values */
|
||||
#define NMC_OF_FLAG_SECTION_PREFIX 0x00000002 /* Use the first value as section prefix for the other field names - just in multiline */
|
||||
#define NMC_OF_FLAG_MAIN_HEADER_ADD 0x00000004 /* Print main header in addition to values/field names */
|
||||
#define NMC_OF_FLAG_MAIN_HEADER_ONLY 0x00000008 /* Print main header only */
|
||||
|
||||
typedef enum {
|
||||
NMC_OF_FLAG_FIELD_NAMES = 0x00000001, /* Print field names instead of values */
|
||||
NMC_OF_FLAG_SECTION_PREFIX = 0x00000002, /* Use the first value as section prefix for the other field names - just in multiline */
|
||||
NMC_OF_FLAG_MAIN_HEADER_ADD = 0x00000004, /* Print main header in addition to values/field names */
|
||||
NMC_OF_FLAG_MAIN_HEADER_ONLY = 0x00000008, /* Print main header only */
|
||||
} NmcOfFlags;
|
||||
|
||||
struct _NMMetaSettingInfoEditor;
|
||||
|
||||
|
|
@ -113,7 +115,7 @@ typedef struct _NmcOutputField {
|
|||
void *value; /* Value of current field - char* or char** (NULL-terminated array) */
|
||||
gboolean value_is_array; /* Whether value is char** instead of char* */
|
||||
gboolean free_value; /* Whether to free the value */
|
||||
guint32 flags; /* Flags - whether and how to print values/field names/headers */
|
||||
NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */
|
||||
NmcTermColor color; /* Use this color to print value */
|
||||
NmcTermFormat color_fmt; /* Use this terminal format to print value */
|
||||
|
||||
|
|
|
|||
|
|
@ -815,7 +815,7 @@ nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx)
|
|||
}
|
||||
|
||||
NmcOutputField *
|
||||
nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags)
|
||||
nmc_dup_fields_array (NmcOutputField fields[], size_t size, NmcOfFlags flags)
|
||||
{
|
||||
NmcOutputField *row;
|
||||
|
||||
|
|
@ -910,7 +910,7 @@ get_value_to_print (NmcColorOption color_option,
|
|||
* of 'field_values' array.
|
||||
*/
|
||||
void
|
||||
print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField *field_values)
|
||||
print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const NmcPrintFields *print_fields, const NmcOutputField *field_values)
|
||||
{
|
||||
GString *str;
|
||||
int width1, width2;
|
||||
|
|
@ -923,10 +923,10 @@ print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_
|
|||
gboolean terse = (nmc_config->print_output == NMC_PRINT_TERSE);
|
||||
gboolean pretty = (nmc_config->print_output == NMC_PRINT_PRETTY);
|
||||
gboolean escape = nmc_config->escape_values;
|
||||
gboolean main_header_add = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ADD;
|
||||
gboolean main_header_only = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ONLY;
|
||||
gboolean field_names = field_values[0].flags & NMC_OF_FLAG_FIELD_NAMES;
|
||||
gboolean section_prefix = field_values[0].flags & NMC_OF_FLAG_SECTION_PREFIX;
|
||||
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;
|
||||
gboolean section_prefix = of_flags & NMC_OF_FLAG_SECTION_PREFIX;
|
||||
gboolean main_header = main_header_add || main_header_only;
|
||||
|
||||
enum { ML_HEADER_WIDTH = 79 };
|
||||
|
|
@ -1123,8 +1123,10 @@ print_data (const NmcConfig *nmc_config, const NmcOutputData *out)
|
|||
guint i;
|
||||
|
||||
for (i = 0; i < out->output_data->len; i++) {
|
||||
print_required_fields (nmc_config, &out->print_fields,
|
||||
g_ptr_array_index (out->output_data, i));
|
||||
const NmcOutputField *field_values = g_ptr_array_index (out->output_data, i);
|
||||
|
||||
print_required_fields (nmc_config, field_values[0].flags,
|
||||
&out->print_fields, field_values);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ GArray *parse_output_fields (const char *fields_str,
|
|||
char *nmc_get_allowed_fields (const NmcOutputField fields_array[], int group_idx);
|
||||
NmcOutputField *nmc_dup_fields_array (NmcOutputField fields[], size_t size, guint32 flags);
|
||||
void nmc_empty_output_fields (NmcOutputData *output_data);
|
||||
void print_required_fields (const NmcConfig *nmc_config, const NmcPrintFields *print_fields, const NmcOutputField field_values[]);
|
||||
void print_required_fields (const NmcConfig *nmc_config, NmcOfFlags of_flags, const NmcPrintFields *print_fields, const NmcOutputField field_values[]);
|
||||
void print_data_prepare_width (GPtrArray *output_data);
|
||||
void print_data (const NmcConfig *nmc_config, const NmcOutputData *out);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue