clix
Single-header file CLI libraries for C
Loading...
Searching...
No Matches
args.h: Customization Points

Overview

Customization points for overriding default behaviors.

Define the following macros before including args.h to override default implementations. You can also use these in your own code for consistency.

Help Formatting

#define ARGS_STR_PREPAD   (2)
 Pre-padding for help text.
#define ARGS_PARAM_OFFSET   (1)
 Offset between argument and parameter in help text.
#define ARGS_HELP_OFFSET   (4)
 Offset from longest argument for help text.
#define ARGS_PRINT_H
 Allow using print.h functions for args_pe, args_pd, args_pi and args_abort.
#define args_po(...)
 Normal print.

Error Handling

#define args_pe(...)
 Error print.
#define args_pd(...)
 Developer-only debug print.
#define args_pi(arg)
 Internal error print, user-facing dev print.
#define args_abort()
 Abort function.
#define ARGS_IMPLICIT_SETS   (64)
 Maximum implicit allocations of argument::set booleans.

Functions

void args_help_print (const char *usage, const char *bin, const char *hint, const char *req, const char *opt)
 Prints generated CLI help output.

Variables

struct args_raw argr
 Global storage of raw argc/argv values.

Macro Definition Documentation

◆ ARGS_STR_PREPAD

#define ARGS_STR_PREPAD   (2)

Pre-padding for help text.

Remarks
Overridable before including args.h.

◆ ARGS_PARAM_OFFSET

#define ARGS_PARAM_OFFSET   (1)

Offset between argument and parameter in help text.

Remarks
Overridable before including args.h.

◆ ARGS_HELP_OFFSET

#define ARGS_HELP_OFFSET   (4)

Offset from longest argument for help text.

Remarks
Overridable before including args.h.

◆ ARGS_PRINT_H

#define ARGS_PRINT_H

Allow using print.h functions for args_pe, args_pd, args_pi and args_abort.

Remarks
Define ARGS_PRINT_H and include print.h before including args.h.
Attention
Temporarily disabled

◆ args_po

#define args_po ( ...)
Value:
printf(__VA_ARGS__)

Normal print.

Remarks
Overridable before including args.h.

◆ args_pe

#define args_pe ( ...)
Value:
fprintf(stderr, __VA_ARGS__)

Error print.

Remarks
Overridable before including args.h.

◆ args_pd

#define args_pd ( ...)
Value:
fprintf(stderr, __VA_ARGS__)

Developer-only debug print.

Note
Only available when NDEBUG is not defined
Remarks
Overridable before including args.h.

◆ args_pi

#define args_pi ( arg)
Value:
args_pe("Internal error for %s\n", arg_str(arg))
#define args_pe(...)
Error print.
Definition args.h:1073

Internal error print, user-facing dev print.

Remarks
Overridable before including args.h.

◆ args_abort

#define args_abort ( )
Value:
abort()

Abort function.

Remarks
Overridable before including args.h.

◆ ARGS_IMPLICIT_SETS

#define ARGS_IMPLICIT_SETS   (64)

Maximum implicit allocations of argument::set booleans.

Remarks
Overridable before including args.h.

Function Documentation

◆ args_help_print()

void args_help_print ( const char * usage,
const char * bin,
const char * hint,
const char * req,
const char * opt )

Prints generated CLI help output.

Create your own help parse callback and call this function from it so you can provide custom usage, hint, req, and opt strings.

Example:

#define ARGS_EXTERN_ARGR
#include "args.h"
static struct arg_callback parse_help(const char *str, void *dest)
{
// help is a flag argument, safe to ignore both
(void)str;
(void)dest;
args_help_print("Usage: ",
argr.v[0],
" [OPTIONS]\n",
"\nRequired options:\n",
"\nOptional options:\n");
exit(EXIT_SUCCESS);
}
ARGUMENT(help) = {
.parse_callback = parse_help,
.help = "Display this help message",
.lopt = "help",
.opt = 'h',
};
#define ARGUMENT(name)
Creates and registers a new argument object.
Definition args.h:146
void args_help_print(const char *usage, const char *bin, const char *hint, const char *req, const char *opt)
Prints generated CLI help output.
struct args_raw argr
Global storage of raw argc/argv values.
Result object returned by parser/validator callbacks.
Definition args.h:315

Outputs: "{usage}{bin}{hint}{req}<required args>\n{opt}<optional args>\n"

Variable Documentation

◆ argr

struct args_raw argr
extern

Global storage of raw argc/argv values.

Note
Available when ARGS_EXTERN_ARGR is defined before including args.h.