mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-05 13:18:20 +03:00
libdm: report: support reporting field IDs in headings
Add new DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS report output flag. If enabled, column IDs are reported instead of column names in report headings. The 'column IDs' are IDs as found in 'const struct dm_report_field_type *fields' array that is passed during report initialization (that is, a call to dm_report_init/dm_report_init_with_selection). In this case, the 'id' dm_report_field_type member is used instead of the 'heading' member.
This commit is contained in:
parent
c4b42e9f59
commit
12b60e7c25
@ -1,5 +1,6 @@
|
||||
Version 1.02.197 -
|
||||
===================================
|
||||
Add DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS to provide alternative headings.
|
||||
|
||||
Version 1.02.196 - 02nd August 2023
|
||||
===================================
|
||||
|
@ -1875,6 +1875,7 @@ const void *dm_report_value_cache_get(struct dm_report *rh, const char *name);
|
||||
#define DM_REPORT_OUTPUT_FIELD_UNQUOTED 0x00000010
|
||||
#define DM_REPORT_OUTPUT_COLUMNS_AS_ROWS 0x00000020
|
||||
#define DM_REPORT_OUTPUT_MULTIPLE_TIMES 0x00000040
|
||||
#define DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS 0x00000080
|
||||
|
||||
struct dm_report *dm_report_init(uint32_t *report_types,
|
||||
const struct dm_report_object_type *types,
|
||||
|
@ -4263,7 +4263,9 @@ static int _report_headings(struct dm_report *rh)
|
||||
|
||||
fields = fp->implicit ? _implicit_report_fields : rh->fields;
|
||||
|
||||
heading = fields[fp->field_num].heading;
|
||||
heading = rh->flags & DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS ?
|
||||
fields[fp->field_num].id : fields[fp->field_num].heading;
|
||||
|
||||
if (rh->flags & DM_REPORT_OUTPUT_ALIGNED) {
|
||||
if (dm_snprintf(buf, buf_size, "%-*.*s",
|
||||
fp->width, fp->width, heading) < 0) {
|
||||
@ -4315,6 +4317,7 @@ static void _recalculate_fields(struct dm_report *rh)
|
||||
struct row *row;
|
||||
struct dm_report_field *field;
|
||||
int len;
|
||||
size_t id_len;
|
||||
|
||||
dm_list_iterate_items(row, &rh->rows) {
|
||||
dm_list_iterate_items(field, &row->fields) {
|
||||
@ -4329,6 +4332,12 @@ static void _recalculate_fields(struct dm_report *rh)
|
||||
field->props->width = len;
|
||||
|
||||
}
|
||||
|
||||
if (rh->flags & DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS) {
|
||||
id_len = strlen(rh->fields[field->props->field_num].id);
|
||||
if (field->props->width < id_len)
|
||||
field->props->width = id_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4740,6 +4749,7 @@ static int _output_as_rows(struct dm_report *rh)
|
||||
struct field_properties *fp;
|
||||
struct dm_report_field *field;
|
||||
struct row *row;
|
||||
const char *heading;
|
||||
|
||||
dm_list_iterate_items(fp, &rh->field_props) {
|
||||
if (fp->flags & FLD_HIDDEN) {
|
||||
@ -4758,7 +4768,10 @@ static int _output_as_rows(struct dm_report *rh)
|
||||
}
|
||||
|
||||
if ((rh->flags & DM_REPORT_OUTPUT_HEADINGS)) {
|
||||
if (!dm_pool_grow_object(rh->mem, fields[fp->field_num].heading, 0)) {
|
||||
heading = rh->flags & DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS ?
|
||||
fields[fp->field_num].id : fields[fp->field_num].heading;
|
||||
|
||||
if (!dm_pool_grow_object(rh->mem, heading, 0)) {
|
||||
log_error("dm_report: Failed to extend row for field name");
|
||||
goto bad;
|
||||
}
|
||||
|
@ -3058,6 +3058,7 @@ const void *dm_report_value_cache_get(struct dm_report *rh, const char *name);
|
||||
#define DM_REPORT_OUTPUT_FIELD_UNQUOTED 0x00000010
|
||||
#define DM_REPORT_OUTPUT_COLUMNS_AS_ROWS 0x00000020
|
||||
#define DM_REPORT_OUTPUT_MULTIPLE_TIMES 0x00000040
|
||||
#define DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS 0x00000080
|
||||
|
||||
struct dm_report *dm_report_init(uint32_t *report_types,
|
||||
const struct dm_report_object_type *types,
|
||||
|
@ -4262,7 +4262,9 @@ static int _report_headings(struct dm_report *rh)
|
||||
|
||||
fields = fp->implicit ? _implicit_report_fields : rh->fields;
|
||||
|
||||
heading = fields[fp->field_num].heading;
|
||||
heading = rh->flags & DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS ?
|
||||
fields[fp->field_num].id : fields[fp->field_num].heading;
|
||||
|
||||
if (rh->flags & DM_REPORT_OUTPUT_ALIGNED) {
|
||||
if (dm_snprintf(buf, buf_size, "%-*.*s",
|
||||
fp->width, fp->width, heading) < 0) {
|
||||
@ -4314,6 +4316,7 @@ static void _recalculate_fields(struct dm_report *rh)
|
||||
struct row *row;
|
||||
struct dm_report_field *field;
|
||||
int len;
|
||||
size_t id_len;
|
||||
|
||||
dm_list_iterate_items(row, &rh->rows) {
|
||||
dm_list_iterate_items(field, &row->fields) {
|
||||
@ -4328,6 +4331,12 @@ static void _recalculate_fields(struct dm_report *rh)
|
||||
field->props->width = len;
|
||||
|
||||
}
|
||||
|
||||
if (rh->flags & DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS) {
|
||||
id_len = strlen(rh->fields[field->props->field_num].id);
|
||||
if (field->props->width < id_len)
|
||||
field->props->width = id_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4739,6 +4748,7 @@ static int _output_as_rows(struct dm_report *rh)
|
||||
struct field_properties *fp;
|
||||
struct dm_report_field *field;
|
||||
struct row *row;
|
||||
const char *heading;
|
||||
|
||||
dm_list_iterate_items(fp, &rh->field_props) {
|
||||
if (fp->flags & FLD_HIDDEN) {
|
||||
@ -4757,7 +4767,10 @@ static int _output_as_rows(struct dm_report *rh)
|
||||
}
|
||||
|
||||
if ((rh->flags & DM_REPORT_OUTPUT_HEADINGS)) {
|
||||
if (!dm_pool_grow_object(rh->mem, fields[fp->field_num].heading, 0)) {
|
||||
heading = rh->flags & DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS ?
|
||||
fields[fp->field_num].id : fields[fp->field_num].heading;
|
||||
|
||||
if (!dm_pool_grow_object(rh->mem, heading, 0)) {
|
||||
log_error("dm_report: Failed to extend row for field name");
|
||||
goto bad;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user