xap/xap_test.c

105 lines
2.8 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
// Macro isnt directly used by XAP
#define VERSION "0.0.1"
2024-05-17 02:50:47 +00:00
#define XAP_DISPLAY_VERSION
2024-05-17 11:57:03 +00:00
#define XAP_USE_COLOR
#define XAP_EXIT_ON_ERROR
2024-05-17 02:50:47 +00:00
#define XAP_IMPL
#include "xap.h"
static size_t DEFAULT_UINT = 420;
static s_size_t DEFAULT_INT = -420;
static float DEFAULT_FLOAT = 69.420;
static bool DEFAULT_BOOL = false;
static xap_arg_t args[] = {
{
2024-05-17 02:50:47 +00:00
.s_long = "str",
.s_short = 's',
.description = "An example how the XAP_ARG_STR type works",
.type = XAP_ARG_STR,
.default_value = "Hello :3"
},
{
2024-05-17 02:50:47 +00:00
.s_long = "uint",
.s_short = 'u',
.description = "An example how the XAP_ARG_UINT type works",
.type = XAP_ARG_UINT,
.default_value = &DEFAULT_UINT
},
{
2024-05-17 02:50:47 +00:00
.s_long = "int",
.s_short = 'i',
.description = "An example how the XAP_ARG_INT type works",
.type = XAP_ARG_INT,
.default_value = &DEFAULT_INT
},
{
2024-05-17 02:50:47 +00:00
.s_long = "float",
.s_short = 'f',
.description = "An example how the XAP_ARG_FLOAT type works",
.type = XAP_ARG_FLOAT,
.default_value = &DEFAULT_FLOAT
},
{
2024-05-17 02:50:47 +00:00
.s_long = "bool",
.s_short = 'b',
.description = "An example how the XAP_ARG_BOOL type works",
.type = XAP_ARG_BOOL,
.default_value = &DEFAULT_BOOL
},
{
2024-05-17 02:50:47 +00:00
.s_long = "toggle",
.s_short = 't',
.description = "An example how the XAP_ARG_STR type works",
.type = XAP_ARG_TOGGLE,
.default_value = NULL // XAP_ARG_STR doesnt accept default values
}
};
2024-05-17 02:50:47 +00:00
int main(int argc, char** argv) {
xap_t xap = {
.description = "Testing program for XAP :3",
.version = VERSION,
.footer = "This pogram is licenced under blah blah blah",
.post_args_name = "files",
.post_args_description = "Files to blah blah :3"
};
2024-05-17 11:57:03 +00:00
xap_arg_t a_req = {
.s_long = "required",
.s_short = 'r',
.description = "A required value",
.type = XAP_ARG_STR,
.default_value = NULL,
.required = true
};
2024-05-17 02:50:47 +00:00
xap_arg_add_arr(&xap, args); // Add from a static arr
xap_arg_add(&xap, a_req); // Add a single arg
// Join 2 xap instances, for some reason idk
// xap_arg_add_many(&xap, xap2->args.items, xap2->args.count);
2024-05-17 02:50:47 +00:00
xap_parse(&xap, argc, argv);
char* v_str = xap_get_arg_value_str(&xap, "str");
2024-05-17 02:50:47 +00:00
size_t* v_uint = xap_get_arg_value_uint(&xap, "uint");
2024-05-17 11:57:03 +00:00
// s_size_t is a macro for ptrdiff_t aka signed size_t
s_size_t* v_int = xap_get_arg_value_int(&xap, "int");
float* v_float = xap_get_arg_value_float(&xap, "float");
bool* v_bool = xap_get_arg_value_bool(&xap, "bool");
2024-05-17 02:50:47 +00:00
// Print all args, for debugging
2024-05-17 02:50:47 +00:00
// xap_print_args(&xap);
2024-05-17 11:57:03 +00:00
2024-05-17 02:50:47 +00:00
}