mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.9 KiB
81 lines
2.9 KiB
10 years ago
|
/*
|
||
|
*
|
||
8 years ago
|
* Copyright 2015 gRPC authors.
|
||
10 years ago
|
*
|
||
8 years ago
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
10 years ago
|
*
|
||
8 years ago
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
10 years ago
|
*
|
||
8 years ago
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
10 years ago
|
*
|
||
|
*/
|
||
|
|
||
7 years ago
|
#ifndef GRPC_TEST_CORE_UTIL_CMDLINE_H
|
||
|
#define GRPC_TEST_CORE_UTIL_CMDLINE_H
|
||
10 years ago
|
|
||
9 years ago
|
#include <grpc/support/port_platform.h>
|
||
|
|
||
8 years ago
|
/** Simple command line parser.
|
||
10 years ago
|
|
||
|
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;
|
||
|
} */
|
||
|
|
||
|
typedef struct gpr_cmdline gpr_cmdline;
|
||
|
|
||
8 years ago
|
/** Construct a command line parser: takes a short description of the tool
|
||
10 years ago
|
doing the parsing */
|
||
7 years ago
|
gpr_cmdline* gpr_cmdline_create(const char* description);
|
||
8 years ago
|
/** Add an integer parameter, with a name (used on the command line) and some
|
||
10 years ago
|
helpful text (used in the command usage) */
|
||
7 years ago
|
void gpr_cmdline_add_int(gpr_cmdline* cl, const char* name, const char* help,
|
||
|
int* value);
|
||
8 years ago
|
/** The same, for a boolean flag */
|
||
7 years ago
|
void gpr_cmdline_add_flag(gpr_cmdline* cl, const char* name, const char* help,
|
||
|
int* value);
|
||
8 years ago
|
/** And for a string */
|
||
7 years ago
|
void gpr_cmdline_add_string(gpr_cmdline* cl, const char* name, const char* help,
|
||
|
const char** value);
|
||
8 years ago
|
/** Set a callback for non-named arguments */
|
||
7 years ago
|
void gpr_cmdline_on_extra_arg(
|
||
7 years ago
|
gpr_cmdline* cl, const char* name, const char* help,
|
||
|
void (*on_extra_arg)(void* user_data, const char* arg), void* user_data);
|
||
8 years ago
|
/** Enable surviving failure: default behavior is to exit the process */
|
||
7 years ago
|
void gpr_cmdline_set_survive_failure(gpr_cmdline* cl);
|
||
8 years ago
|
/** Parse the command line; returns 1 on success, on failure either dies
|
||
9 years ago
|
(by default) or returns 0 if gpr_cmdline_set_survive_failure() has been
|
||
|
called */
|
||
7 years ago
|
int gpr_cmdline_parse(gpr_cmdline* cl, int argc, char** argv);
|
||
8 years ago
|
/** Destroy the parser */
|
||
7 years ago
|
void gpr_cmdline_destroy(gpr_cmdline* cl);
|
||
8 years ago
|
/** Get a string describing usage */
|
||
7 years ago
|
char* gpr_cmdline_usage_string(gpr_cmdline* cl, const char* argv0);
|
||
10 years ago
|
|
||
7 years ago
|
#endif /* GRPC_TEST_CORE_UTIL_CMDLINE_H */
|