[common] add getValues callback for options

This commit is contained in:
Geoffrey McRae 2019-05-12 16:13:50 +10:00
parent 5d69d2aba9
commit e22f33a44b
4 changed files with 19 additions and 8 deletions

View File

@ -1 +1 @@
a12-183-g0090580a64+1
a12-184-g5d69d2aba9+1

View File

@ -6,6 +6,7 @@ include_directories(
)
set(SOURCES
src/stringlist.c
src/option.c
)

View File

@ -17,8 +17,8 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdint.h>
#include <stdbool.h>
#include "common/stringlist.h"
enum OptionType
{
@ -50,6 +50,7 @@ struct Option
bool (*parser )(struct Option * opt, const char * str);
bool (*validator)(struct Option * opt, const char ** error);
char * (*toString )(struct Option * opt);
StringList (*getValues)(struct Option * opt);
void (*printHelp)();
};

View File

@ -464,6 +464,15 @@ bool option_validate()
if (error)
printf("\n Error: %s\n", error);
if (o->getValues)
{
StringList values = o->getValues(o);
printf("\nValid values are:\n\n");
for(unsigned int v = 0; v < stringlist_count(values); ++v)
printf(" * %s\n", stringlist_at(values, v));
stringlist_free(&values);
}
if (o->printHelp)
{
printf("\n");