2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef GIMBAL_CMD_PARSER_H
15#define GIMBAL_CMD_PARSER_H
20
21
22
24#define GBL_CMD_PARSER(self) (GBL_CAST(GblCmdParser, self))
26#define GBL_CMD_PARSER_GET_CLASS(self) (GBL_CLASSOF(GblCmdParser, self))
29#define GBL_SELF_TYPE GblCmdParser
42
43
44
45
46
47
48
49
62
63
64
65
66
67
68
69
70
71
72
73
74
75
89 (allowUnknownOptions, GBL_GENERIC, (READ, WRITE),
GBL_BOOL_TYPE),
90 (firstArgAsExecutable, GBL_GENERIC, (READ, WRITE),
GBL_BOOL_TYPE),
91 (enableVersionOption, GBL_GENERIC, (READ, WRITE),
GBL_BOOL_TYPE),
92 (enableHelpOption, GBL_GENERIC, (READ, WRITE),
GBL_BOOL_TYPE),
99 (parsePrePass, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pInitialArgs)),
100 (parsePostPass, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pRemainingArgs)),
101 (parseExtraArgs, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pExtraArgs)),
102 (parseUnknownOptions, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pRemaininArgs)),
103 (parseError, (GBL_INSTANCE_TYPE, pReceiver), (GBL_ENUM_TYPE, errorCode))
111
112
113
121
122
123
124
146
147
148
149
175
176
177
#define GBL_CLASS_CAST(cType, klass)
GblCmdParser * GblCmdParser_create(void)
Creates a GblCmdParser object, initializes it, and returns a pointer to it.
GblRefCount GblCmdParser_unref(GblCmdParser *pSelf)
Unreferences a GblCmdParser, destroying it if it's the last one, returning the remaining reference co...
GblType GblCmdParser_type(void)
Returns the GblType UUID associated with GblCmdParser.
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_CLASS_DERIVE(...)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)
#define GBL_BOOL_TYPE
Builtin ID for boolean GblVariant type.
#define GBL_PROPERTIES(object,...)
Declares a list of properties for the given object/instance structure.
#define GBL_SIGNALS(instanceStruct,...)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
GblRingList GblStringList
List of strings with array-like API.
const char GblStringRef
Reference-counted, const char*-compatible string type.
Attributes of a single command-line argument.
GblStringRef * pName
Name of the command-line argument.
GblStringRef * pDesc
Description of the command-line argument.
General-purpose command-line argument parser.
size_t GblCmdParser_positionalArgValueCount(const GblCmdParser *pSelf)
After parsing, this function returns the number of positional arguments extracted.
const GblStringList * GblCmdParser_positionalArgValues(const GblCmdParser *pSelf)
After parsing, returns the GblStringList maintained internally, containing the extracted positional a...
const GblStringList * GblCmdParser_unknownOptions(const GblCmdParser *pSelf)
After parsing, retuns a GblStringList to the internally maintained list of unknown command-line optio...
GblOptionGroup * GblCmdParser_optionGroup(const GblCmdParser *pSelf, size_t idx)
Returns a pointer to the GblOptionGroup at the given index.
uint8_t firstArgAsExecutable
Toggle for determining whether to treat the first argument as the executable name.
GblOptionGroup * GblCmdParser_mainOptionGroup(const GblCmdParser *pSelf)
Returns the GblOptionGroup previously set as the main option group for the GblCmdParser.
GBL_RESULT GblCmdParser_addPositionalArg(GblCmdParser *pSelf, const char *pName, const char *pDesc)
Dynamically creates a GblCmdArg struct from the given args and adds it to the internal list.
GBL_RESULT GblCmdParser_parse(GblCmdParser *pSelf, GblStringList *pArgs)
Parses the list of arguments given by pArgs, populating internal structures, and returning the result...
GBL_RESULT GblCmdParser_positionalArgValue(const GblCmdParser *pSelf, size_t index, GblType toType, void *pData)
After parsing, this function converts the value of the argument at the given index to the desired toT...
GBL_RESULT GblCmdParser_setOptionGroups(GblCmdParser *pSelf, GblOptionGroup **ppGroups)
Sets the internal array of option groups to the list of pointers given by the ppGroups array,...
const GblStringRef * GblCmdParser_executable(const GblCmdParser *pSelf)
After parsing, returns a GblStringRef to the name of the current executable (first positional argumen...
size_t GblCmdParser_optionGroupCount(const GblCmdParser *pSelf)
Returns the number of option groups held within the internal list of them.
GBL_RESULT GblCmdParser_clearPositionalArgs(GblCmdParser *pSelf)
Clears the currently held internal list of GblCmdArg structures, resetting its size to 0.
GBL_RESULT parseResult
Result of last parse operation.
GBL_RESULT GblCmdParser_addOptionGroup(GblCmdParser *pSelf, GblOptionGroup *pGroup)
Adds the GblOptionGroup pGroup to the list of option groups handled by the GblCmdParser.
size_t GblCmdParser_positionalArgCount(const GblCmdParser *pSelf)
Returns the size of the internally managed list of GblCmdArg structures represengin command-line argu...
GblStringRef * pErrorMsg
Current, pending error message.
uint8_t allowExtraArgs
Toggle for allowing extra positional arguments beyond the ones added.
GBL_RESULT GblCmdParser_setPositionalArgs(GblCmdParser *pSelf, const GblCmdArg *pArgs)
Sets the 0-terminated list of arguments pointed to by pArgs as the new positional argument list.
GBL_RESULT GblCmdParser_setMainOptionGroup(GblCmdParser *pSelf, GblOptionGroup *pGroup)
Sets the main option group for the parser to the one given by pGroup, returning the result.
uint8_t enableVersionOption
Toggle for optionally enabling a version command-line option.
const GblCmdArg * GblCmdParser_positionalArg(const GblCmdParser *pSelf, size_t index)
Returns a pointer to the GblCmdArg structure in the internally maintained list at the given index.
uint8_t enableHelpOption
Toggle for optionally enabling an autogenerated help option.
uint8_t allowUnknownOptions
Toggle for allowing unknown options not handled by a GblCmdOptionGroup.
GblOptionGroup * GblCmdParser_findOptionGroup(const GblCmdParser *pSelf, const char *pName)
Finds a GblOptionGroup from the internal list by its GblObject::name.