Make delimiter of multiple attribute value from immlist configurable
Update option --pretty-print will not support print with option --atribute
---
src/imm/tools/imm_list.c | 78 +++++++++++++++++++++++++++++++++++++++---------
1 file changed, 64 insertions(+), 14 deletions(-)
diff --git a/src/imm/tools/imm_list.c b/src/imm/tools/imm_list.c
index d1dc422..09222de 100644
--- a/src/imm/tools/imm_list.c
+++ b/src/imm/tools/imm_list.c
@@ -72,13 +72,18 @@ static void usage(const char *progname)
printf("\t-h, --help - display this help and exit\n");
printf(
"\t-p, --pretty-print=<yes|no> - select pretty print, default
yes\n");
+ printf(
+ "\tdo not support pretty print with option -a, --attribute=NAME\n");
+ printf(
+ "\t-d, --delimiter=<CHARACTER> - format multi attribute value\n");
printf("\t-t, --timeout <sec>\n");
printf("\t\tutility timeout in seconds\n");
printf("\nEXAMPLE\n");
printf("\timmlist -a saAmfApplicationAdminState safApp=OpenSAF\n");
printf("\timmlist safApp=myApp1 safApp=myApp2\n");
- printf("\timmlist --pretty-print=no -a saAmfAppType safApp=OpenSAF\n");
+ printf("\timmlist --pretty-print=no safApp=OpenSAF\n");
+ printf("\timmlist -d '|' safApp=OpenSAF\n");
}
static void print_attr_value_raw(SaImmValueTypeT attrValueType,
@@ -141,19 +146,19 @@ static void print_attr_value(SaImmValueTypeT
attrValueType,
{
switch (attrValueType) {
case SA_IMM_ATTR_SAINT32T:
- printf("%d (0x%x) ", *((SaInt32T *)attrValue),
+ printf("%d (0x%x)", *((SaInt32T *)attrValue),
*((SaInt32T *)attrValue));
break;
case SA_IMM_ATTR_SAUINT32T:
- printf("%u (0x%x) ", *((SaUint32T *)attrValue),
+ printf("%u (0x%x)", *((SaUint32T *)attrValue),
*((SaUint32T *)attrValue));
break;
case SA_IMM_ATTR_SAINT64T:
- printf("%lld (0x%llx) ", *((SaInt64T *)attrValue),
+ printf("%lld (0x%llx)", *((SaInt64T *)attrValue),
*((SaInt64T *)attrValue));
break;
case SA_IMM_ATTR_SAUINT64T:
- printf("%llu (0x%llx) ", *((SaUint64T *)attrValue),
+ printf("%llu (0x%llx)", *((SaUint64T *)attrValue),
*((SaUint64T *)attrValue));
break;
case SA_IMM_ATTR_SATIMET: {
@@ -163,24 +168,24 @@ static void print_attr_value(SaImmValueTypeT
attrValueType,
ctime_r(&time, buf);
buf[strlen(buf) - 1] = '\0'; /* Remove new line */
- printf("%llu (0x%llx, %s) ", *((SaTimeT *)attrValue),
+ printf("%llu (0x%llx, %s)", *((SaTimeT *)attrValue),
*((SaTimeT *)attrValue), buf);
break;
}
case SA_IMM_ATTR_SAFLOATT:
- printf("%.8g ", *((SaFloatT *)attrValue));
+ printf("%.8g", *((SaFloatT *)attrValue));
break;
case SA_IMM_ATTR_SADOUBLET:
- printf("%.17g ", *((SaDoubleT *)attrValue));
+ printf("%.17g", *((SaDoubleT *)attrValue));
break;
case SA_IMM_ATTR_SANAMET: {
SaNameT *myNameT = (SaNameT *)attrValue;
- printf("%s (%zu) ", saAisNameBorrow(myNameT),
+ printf("%s (%zu)", saAisNameBorrow(myNameT),
strlen(saAisNameBorrow(myNameT)));
break;
}
case SA_IMM_ATTR_SASTRINGT:
- printf("%s ", *((char **)attrValue));
+ printf("%s", *((char **)attrValue));
break;
case SA_IMM_ATTR_SAANYT: {
SaAnyT *anyp = (SaAnyT *)attrValue;
@@ -404,6 +409,8 @@ static void display_class_definition(const SaImmClassNameT
className,
static void display_object(const char *name,
SaImmAccessorHandleT accessorHandle,
int pretty_print,
+ int delimiter_print,
+ char *character,
const SaImmAttrNameT *attributeNames)
{
int i = 0, j;
@@ -411,6 +418,7 @@ static void display_object(const char *name,
SaNameT objectName;
SaAisErrorT error;
SaImmAttrValuesT_2 **attributes;
+ char *seperate_character = "";
saAisNameLend(name, &objectName);
@@ -428,6 +436,14 @@ static void display_object(const char *name,
exit(EXIT_FAILURE);
}
+ if (delimiter_print)
+ seperate_character = character;
+ else
+ if (pretty_print)
+ seperate_character = " ";
+ else
+ seperate_character = ":";
+
if (pretty_print) {
printf("%-50s %-12s Value(s)\n", "Name", "Type");
printf(
@@ -436,9 +452,13 @@ static void display_object(const char *name,
printf("\n%-50s %-12s ", attr->attrName,
get_attr_type_name(attr->attrValueType));
if (attr->attrValuesNumber > 0) {
- for (j = 0; j < attr->attrValuesNumber; j++)
+ for (j = 0; j < attr->attrValuesNumber; j++) {
print_attr_value(attr->attrValueType,
attr->attrValues[j]);
+ if ((j + 1) < attr->attrValuesNumber)
+ printf("%s",
+ seperate_character);
+ }
} else
printf("<Empty>");
}
@@ -452,7 +472,8 @@ static void display_object(const char *name,
attr->attrValueType,
attr->attrValues[j]);
if ((j + 1) < attr->attrValuesNumber)
- printf(":");
+ printf("%s",
+ seperate_character);
}
printf("\n");
} else
@@ -470,6 +491,7 @@ int main(int argc, char *argv[])
{"timeout", required_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
{"pretty-print", required_argument, 0, 'p'},
+ {"delimiter", required_argument, 0, 'd'},
{0, 0, 0, 0}};
SaAisErrorT error;
SaImmHandleT immHandle;
@@ -481,6 +503,9 @@ int main(int argc, char *argv[])
int class_desc_print = 0;
int rc = EXIT_SUCCESS;
unsigned long timeoutVal = 60;
+ int delimiter_print = 0;
+ char *character = "";
+ int atribute_set = 0;
/* Support for long DN */
setenv("SA_ENABLE_EXTENDED_NAMES", "1", 1);
@@ -490,7 +515,7 @@ int main(int argc, char *argv[])
osaf_extended_name_init();
while (1) {
- c = getopt_long(argc, argv, "a:p:t:ch", long_options, NULL);
+ c = getopt_long(argc, argv, "a:d:p:t:ch", long_options, NULL);
if (c ==
-1) /* have all command-line options have been parsed? */
@@ -502,6 +527,7 @@ int main(int argc, char *argv[])
attributeNames, ++len * sizeof(SaImmAttrNameT));
attributeNames[len - 2] = strdup(optarg);
attributeNames[len - 1] = NULL;
+ atribute_set = 1;
pretty_print = 0;
break;
case 'c':
@@ -517,6 +543,21 @@ int main(int argc, char *argv[])
case 'p':
if (!strcasecmp(optarg, "no"))
pretty_print = 0;
+ else
+ pretty_print = 1;
+ break;
+ case 'd':
+ character = optarg;
+ size_t len = 0;
+ len = strlen(character);
+ if (len == 1) {
+ delimiter_print = 1;
+ } else {
+ fprintf(
+ stderr, "Illegal delimiter argument."
+ " Valid value is one character\n");
+ exit(EXIT_FAILURE);
+ }
break;
default:
fprintf(stderr,
@@ -537,6 +578,14 @@ int main(int argc, char *argv[])
goto done;
}
+ if (atribute_set && pretty_print) {
+ fprintf(
+ stderr,
+ "error - disallow --pretty-print=yes with option -a\n");
+ rc = EXIT_FAILURE;
+ goto done;
+ }
+
immutilWrapperProfile.errorsAreFatal = 0;
immutilWrapperProfile.nTries = timeoutVal;
immutilWrapperProfile.retryInterval = 1000;
@@ -570,7 +619,8 @@ int main(int argc, char *argv[])
* attributes for. */
while (optind < argc) {
display_object(argv[optind], accessorHandle,
- pretty_print, attributeNames);
+ pretty_print, delimiter_print,
+ character, attributeNames);
optind++;
}
--
2.7.4
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel