summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2014-06-16 14:06:04 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2014-06-17 16:27:21 +0200
commita075ec15c4a8e704fbb9519326d0c97371ead2f3 (patch)
treea2b42b2caa13c68aa2cc3ee870e2d7f25e3cfce7
parent6d667adeeab7eb7b88a596ebd998fa0a32a4f61c (diff)
downloadlvm2-a075ec15c4a8e704fbb9519326d0c97371ead2f3.tar.gz
report: select: show field type in field list if in context of selection
When the field list is displayed as help for constructing selection criteria, show also the field value type. This is useful for users to know what set of operators are allowed for the type - the subsequent "Selection operands" section in the help output summarize all known types that can be used in selection.
-rw-r--r--libdm/libdm-report.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index df29b6b17..1c3516672 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -472,10 +472,22 @@ void dm_report_field_set_value(struct dm_report_field *field, const void *value,
log_warn(INTERNAL_ERROR "Using string as sort value for numerical field.");
}
+static const char *_get_field_type_name(unsigned field_type)
+{
+ switch (field_type) {
+ case DM_REPORT_FIELD_TYPE_STRING: return "string";
+ case DM_REPORT_FIELD_TYPE_NUMBER: return "number";
+ case DM_REPORT_FIELD_TYPE_SIZE: return "size";
+ case DM_REPORT_FIELD_TYPE_STRING_LIST: return "string list";
+ default: return "unknown";
+ }
+}
+
/*
* show help message
*/
-static void _display_fields(struct dm_report *rh, int display_all_fields_item)
+static void _display_fields(struct dm_report *rh, int display_all_fields_item
+ int display_field_types)
{
uint32_t f;
const struct dm_report_object_type *type;
@@ -511,7 +523,10 @@ static void _display_fields(struct dm_report *rh, int display_all_fields_item)
}
/* FIXME Add line-wrapping at terminal width (or 80 cols) */
- log_warn(" %-*s - %s", (int) id_len, rh->fields[f].id, rh->fields[f].desc);
+ log_warn(" %-*s - %s%s%s%s", (int) id_len, rh->fields[f].id, rh->fields[f].desc,
+ display_field_types ? " [" : "",
+ display_field_types ? _get_field_type_name(rh->fields[f].flags & DM_REPORT_FIELD_TYPE_MASK) : "",
+ display_field_types ? "]" : "");
last_desc = desc;
}
}
@@ -770,7 +785,7 @@ static int _parse_fields(struct dm_report *rh, const char *format,
we++;
if (!_field_match(rh, ws, (size_t) (we - ws), report_type_only)) {
- _display_fields(rh, 1);
+ _display_fields(rh, 1, 0);
log_warn(" ");
if (strcasecmp(ws, DM_REPORT_FIELD_RESERVED_NAME_HELP) &&
strcmp(ws, DM_REPORT_FIELD_RESERVED_NAME_HELP_ALT))
@@ -800,7 +815,7 @@ static int _parse_keys(struct dm_report *rh, const char *keys,
while (*we && *we != ',')
we++;
if (!_key_match(rh, ws, (size_t) (we - ws), report_type_only)) {
- _display_fields(rh, 1);
+ _display_fields(rh, 1, 0);
log_warn(" ");
if (strcasecmp(ws, DM_REPORT_FIELD_RESERVED_NAME_HELP) &&
strcmp(ws, DM_REPORT_FIELD_RESERVED_NAME_HELP_ALT))
@@ -1914,7 +1929,7 @@ static struct selection_node *_parse_selection(struct dm_report *rh,
c = we[0];
tmp = (char *) we;
tmp[0] = '\0';
- _display_fields(rh, 0);
+ _display_fields(rh, 0, 1);
log_warn(" ");
log_error("Unrecognised selection field: %s", ws);
tmp[0] = c;
@@ -2121,7 +2136,7 @@ struct dm_report *dm_report_init_with_selection(uint32_t *report_types,
if (!strcasecmp(selection, DM_REPORT_FIELD_RESERVED_NAME_HELP) ||
!strcmp(selection, DM_REPORT_FIELD_RESERVED_NAME_HELP_ALT)) {
- _display_fields(rh, 0);
+ _display_fields(rh, 0, 1);
log_warn(" ");
_display_selection_help(rh);
dm_report_free(rh);