[common] option: send all output to stderr

This commit is contained in:
Geoffrey McRae 2024-03-04 21:21:16 +11:00
parent bfadf0a427
commit d81395b672

View File

@ -704,23 +704,24 @@ bool option_validate(void)
if (invalid) if (invalid)
{ {
printf("\nInvalid value provided to the option: %s:%s\n", o->module, o->name); fprintf(stderr, "\nInvalid value provided to the option: %s:%s\n",
o->module, o->name);
if (error) if (error)
printf("\n Error: %s\n", error); fprintf(stderr, "\n Error: %s\n", error);
if (o->getValues) if (o->getValues)
{ {
StringList values = o->getValues(o); StringList values = o->getValues(o);
printf("\nValid values are:\n\n"); fprintf(stderr, "\nValid values are:\n\n");
for(unsigned int v = 0; v < stringlist_count(values); ++v) for(unsigned int v = 0; v < stringlist_count(values); ++v)
printf(" * %s\n", stringlist_at(values, v)); fprintf(stderr, " * %s\n", stringlist_at(values, v));
stringlist_free(&values); stringlist_free(&values);
} }
if (o->printHelp) if (o->printHelp)
{ {
printf("\n"); fprintf(stderr, "\n");
o->printHelp(); o->printHelp();
} }
@ -729,34 +730,33 @@ bool option_validate(void)
} }
if (!ok) if (!ok)
printf("\n"); fprintf(stderr, "\n");
return ok; return ok;
} }
void option_print_hrule(char * headerLine, int maxLen, char ruleChar) void option_print_hrule(char * headerLine, int maxLen, char ruleChar)
{ {
printf(" +%c", ruleChar); fprintf(stderr, " +%c", ruleChar);
for (int i = 0; i < maxLen; i++) for (int i = 0; i < maxLen; i++)
{ {
if(i < strlen(headerLine)) if(i < strlen(headerLine))
{ {
if (headerLine[i] == '|') if (headerLine[i] == '|')
{ {
putc('+', stdout); putc('+', stderr);
continue; continue;
} }
} }
putc(ruleChar, stdout); putc(ruleChar, stderr);
} }
printf("%c+\n", ruleChar); fprintf(stderr, "%c+\n", ruleChar);
} }
void option_print(void) void option_print(void)
{ {
printf( fprintf(stderr, "The following is a complete list of options accepted by this "
"The following is a complete list of options accepted by this application\n\n" "application\n\n");
);
for(int g = 0; g < state.gCount; ++g) for(int g = 0; g < state.gCount; ++g)
{ {
@ -850,7 +850,7 @@ void option_print(void)
} }
char * line = stringlist_at(lines, i); char * line = stringlist_at(lines, i);
printf(" | %-*s |\n", maxLen, line); fprintf(stderr, " | %-*s |\n", maxLen, line);
if (i == 0) if (i == 0)
{ {
@ -866,7 +866,7 @@ void option_print(void)
stringlist_free(&lines); stringlist_free(&lines);
printf("\n"); fprintf(stderr, "\n");
} }
} }