mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[common] add getValues callback for options
This commit is contained in:
parent
5d69d2aba9
commit
e22f33a44b
@ -6,6 +6,7 @@ include_directories(
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
|
src/stringlist.c
|
||||||
src/option.c
|
src/option.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "common/stringlist.h"
|
||||||
|
|
||||||
enum OptionType
|
enum OptionType
|
||||||
{
|
{
|
||||||
@ -33,9 +33,9 @@ struct Option;
|
|||||||
|
|
||||||
struct Option
|
struct Option
|
||||||
{
|
{
|
||||||
const char * module;
|
const char * module;
|
||||||
const char * name;
|
const char * name;
|
||||||
const char * description;
|
const char * description;
|
||||||
|
|
||||||
enum OptionType type;
|
enum OptionType type;
|
||||||
union
|
union
|
||||||
@ -47,9 +47,10 @@ struct Option
|
|||||||
}
|
}
|
||||||
value;
|
value;
|
||||||
|
|
||||||
bool (*parser )(struct Option * opt, const char * str);
|
bool (*parser )(struct Option * opt, const char * str);
|
||||||
bool (*validator)(struct Option * opt, const char ** error);
|
bool (*validator)(struct Option * opt, const char ** error);
|
||||||
char * (*toString )(struct Option * opt);
|
char * (*toString )(struct Option * opt);
|
||||||
|
StringList (*getValues)(struct Option * opt);
|
||||||
void (*printHelp)();
|
void (*printHelp)();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -464,6 +464,15 @@ bool option_validate()
|
|||||||
if (error)
|
if (error)
|
||||||
printf("\n Error: %s\n", 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)
|
if (o->printHelp)
|
||||||
{
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user