Elektra
0.9.8
|
INTERNAL header for libelektra-opts. More...
#include <kdb.h>
Functions | |
int | elektraGetOpts (KeySet *ks, int argc, const char **argv, const char **envp, Key *parentKey) |
This functions parses a specification of program options, together with a list of arguments and environment variables to extract the option values. More... | |
char * | elektraGetOptsHelpMessage (Key *helpKey, const char *usage, const char *prefix) |
Extracts the help message from the helpKey used in elektraGetOpts(). More... | |
INTERNAL header for libelektra-opts.
int elektraGetOpts | ( | KeySet * | ks, |
int | argc, | ||
const char ** | argv, | ||
const char ** | envp, | ||
Key * | parentKey | ||
) |
This functions parses a specification of program options, together with a list of arguments and environment variables to extract the option values.
The options have to be defined in the metadata of keys in the spec namespace. If an option value is found for any of the given keys, a new key with the same path but inside the proc namespace will be inserted into ks
. This enables a cascading lookup to find these values.
Take look at https://www.libelektra.org/tutorials/command-line-options for information on how exactly the specification works.
NOTE: Per default option processing DOES NOT stop, when a non-option string is encountered in argv
. If you want processing to stop, set the metadata posixly = 1
on parentKey
.
ks | The KeySet containing the specification for the options. |
argc | The number of strings in argv. |
argv | The arguments to be processed. |
envp | A list of environment variables. This needs to be a null-terminated list of strings of the format 'KEY=VALUE'. |
parentKey | The parent key below which the function will search for option specifications. Also used for error reporting. The key will be translated into the spec namespace automatically, e.g. 'user:/test/parent' will be translated into 'spec:/test/parent', before checking against spec keys. |
0 | on success, this is the only case in which ks will be modified |
-1 | on error, the error will be set as metadata in errorKey |
1 | if the help option --help was found, use elektraGetOptsHelpMessage() access the generated help message |
char* elektraGetOptsHelpMessage | ( | Key * | helpKey, |
const char * | usage, | ||
const char * | prefix | ||
) |
Extracts the help message from the helpKey
used in elektraGetOpts().
helpKey | The same Key as passed to elektraGetOpts() as parentKey. |
usage | If this is not NULL, it will be used instead of the default usage line. Use elektraGetOptsHelpCommand() to check which command was invoked to get the right usage line. |
prefix | If this is not NULL, it will be inserted between the usage line and the options list. |
helpKey
, or NULL if no help message was found. The returned string has to be freed with elektraFree().