GRPC Core
4.0.0
|
#include <grpc/support/port_platform.h>
Go to the source code of this file.
Typedefs | |
typedef struct gpr_cmdline | gpr_cmdline |
Simple command line parser. More... | |
Functions | |
GPRAPI gpr_cmdline * | gpr_cmdline_create (const char *description) |
Construct a command line parser: takes a short description of the tool doing the parsing. More... | |
GPRAPI void | gpr_cmdline_add_int (gpr_cmdline *cl, const char *name, const char *help, int *value) |
Add an integer parameter, with a name (used on the command line) and some helpful text (used in the command usage) More... | |
GPRAPI void | gpr_cmdline_add_flag (gpr_cmdline *cl, const char *name, const char *help, int *value) |
The same, for a boolean flag. More... | |
GPRAPI void | gpr_cmdline_add_string (gpr_cmdline *cl, const char *name, const char *help, char **value) |
And for a string. More... | |
GPRAPI void | gpr_cmdline_on_extra_arg (gpr_cmdline *cl, const char *name, const char *help, void(*on_extra_arg)(void *user_data, const char *arg), void *user_data) |
Set a callback for non-named arguments. More... | |
GPRAPI void | gpr_cmdline_set_survive_failure (gpr_cmdline *cl) |
Enable surviving failure: default behavior is to exit the process. More... | |
GPRAPI int | gpr_cmdline_parse (gpr_cmdline *cl, int argc, char **argv) |
Parse the command line; returns 1 on success, on failure either dies (by default) or returns 0 if gpr_cmdline_set_survive_failure() has been called. More... | |
GPRAPI void | gpr_cmdline_destroy (gpr_cmdline *cl) |
Destroy the parser. More... | |
GPRAPI char * | gpr_cmdline_usage_string (gpr_cmdline *cl, const char *argv0) |
Get a string describing usage. More... | |
typedef struct gpr_cmdline gpr_cmdline |
Simple command line parser.
Supports flags that can be specified as -foo, –foo, –no-foo, -no-foo, etc And integers, strings that can be specified as -foo=4, -foo blah, etc
No support for short command line options (but we may get that in the future.)
Usage (for a program with a single flag argument 'foo'):
int main(int argc, char **argv) { gpr_cmdline *cl; int verbose = 0;
cl = gpr_cmdline_create("My cool tool"); gpr_cmdline_add_int(cl, "verbose", "Produce verbose output?", &verbose); gpr_cmdline_parse(cl, argc, argv); gpr_cmdline_destroy(cl);
if (verbose) { gpr_log(GPR_INFO, "Goodbye cruel world!"); }
return 0; }
GPRAPI void gpr_cmdline_add_flag | ( | gpr_cmdline * | cl, |
const char * | name, | ||
const char * | help, | ||
int * | value | ||
) |
The same, for a boolean flag.
GPRAPI void gpr_cmdline_add_int | ( | gpr_cmdline * | cl, |
const char * | name, | ||
const char * | help, | ||
int * | value | ||
) |
Add an integer parameter, with a name (used on the command line) and some helpful text (used in the command usage)
GPRAPI void gpr_cmdline_add_string | ( | gpr_cmdline * | cl, |
const char * | name, | ||
const char * | help, | ||
char ** | value | ||
) |
And for a string.
GPRAPI gpr_cmdline* gpr_cmdline_create | ( | const char * | description | ) |
Construct a command line parser: takes a short description of the tool doing the parsing.
GPRAPI void gpr_cmdline_destroy | ( | gpr_cmdline * | cl | ) |
Destroy the parser.
GPRAPI void gpr_cmdline_on_extra_arg | ( | gpr_cmdline * | cl, |
const char * | name, | ||
const char * | help, | ||
void(*)(void *user_data, const char *arg) | on_extra_arg, | ||
void * | user_data | ||
) |
Set a callback for non-named arguments.
GPRAPI int gpr_cmdline_parse | ( | gpr_cmdline * | cl, |
int | argc, | ||
char ** | argv | ||
) |
Parse the command line; returns 1 on success, on failure either dies (by default) or returns 0 if gpr_cmdline_set_survive_failure() has been called.
GPRAPI void gpr_cmdline_set_survive_failure | ( | gpr_cmdline * | cl | ) |
Enable surviving failure: default behavior is to exit the process.
GPRAPI char* gpr_cmdline_usage_string | ( | gpr_cmdline * | cl, |
const char * | argv0 | ||
) |
Get a string describing usage.