grpc_cli: allow multiple colon-separated paths in --proto_path (#24187)
Co-authored-by: Yash Tibrewal <yashkt@google.com> Co-authored-by: AJ Heller <hork@google.com>
This commit is contained in:
parent
d469db3fbb
commit
a985978d82
|
|
@ -176,7 +176,8 @@ We can send RPCs to a server and get responses using `grpc_cli call` command.
|
|||
```
|
||||
|
||||
If the proto file is not under the current directory, you can use
|
||||
`--proto_path` to specify a new search root.
|
||||
`--proto_path` to specify new search roots
|
||||
(separated by colon on Mac/Linux/Cygwin or semicolon on Windows).
|
||||
|
||||
Note that the tool will always attempt to use the reflection service first,
|
||||
falling back to local proto files if the service is not found. Use
|
||||
|
|
|
|||
|
|
@ -52,7 +52,9 @@ ABSL_FLAG(bool, remotedb, true,
|
|||
"Use server types to parse and format messages");
|
||||
ABSL_FLAG(std::string, metadata, "",
|
||||
"Metadata to send to server, in the form of key1:val1:key2:val2");
|
||||
ABSL_FLAG(std::string, proto_path, ".", "Path to look for the proto file.");
|
||||
ABSL_FLAG(std::string, proto_path, ".",
|
||||
"Path to look for the proto file. "
|
||||
"Multiple paths can be separated by " GRPC_CLI_PATH_SEPARATOR);
|
||||
ABSL_FLAG(std::string, protofiles, "", "Name of the proto file.");
|
||||
ABSL_FLAG(bool, binary_input, false, "Input in binary format");
|
||||
ABSL_FLAG(bool, binary_output, false, "Output in binary format");
|
||||
|
|
@ -489,8 +491,9 @@ bool GrpcTool::CallMethod(int argc, const char** argv,
|
|||
" <request> ; Text protobuffer (overrides infile)\n"
|
||||
" --protofiles ; Comma separated proto files used as a"
|
||||
" fallback when parsing request/response\n"
|
||||
" --proto_path ; The search path of proto files, valid"
|
||||
" only when --protofiles is given\n"
|
||||
" --proto_path ; The search paths of proto files"
|
||||
" (" GRPC_CLI_PATH_SEPARATOR
|
||||
" separated), valid only when --protofiles is given\n"
|
||||
" --noremotedb ; Don't attempt to use reflection service"
|
||||
" at all\n"
|
||||
" --metadata ; The metadata to be sent to the server\n"
|
||||
|
|
@ -856,8 +859,9 @@ bool GrpcTool::ParseMessage(int argc, const char** argv,
|
|||
" <message> ; Text protobuffer (overrides --infile)\n"
|
||||
" --protofiles ; Comma separated proto files used as a"
|
||||
" fallback when parsing request/response\n"
|
||||
" --proto_path ; The search path of proto files, valid"
|
||||
" only when --protofiles is given\n"
|
||||
" --proto_path ; The search paths of proto files"
|
||||
" (" GRPC_CLI_PATH_SEPARATOR
|
||||
" separated), valid only when --protofiles is given\n"
|
||||
" --noremotedb ; Don't attempt to use reflection service"
|
||||
" at all\n"
|
||||
" --infile ; Input filename (defaults to stdin)\n"
|
||||
|
|
@ -946,7 +950,9 @@ bool GrpcTool::ToText(int argc, const char** argv, const CliCredentials& cred,
|
|||
" grpc_cli totext <protofiles> <type>\n"
|
||||
" <protofiles> ; Comma separated list of proto files\n"
|
||||
" <type> ; Protocol buffer type name\n"
|
||||
" --proto_path ; The search path of proto files\n"
|
||||
" --proto_path ; The search paths of proto files"
|
||||
" (" GRPC_CLI_PATH_SEPARATOR
|
||||
" separated)\n"
|
||||
" --infile ; Input filename (defaults to stdin)\n"
|
||||
" --outfile ; Output filename (defaults to stdout)\n");
|
||||
|
||||
|
|
@ -964,7 +970,9 @@ bool GrpcTool::ToJson(int argc, const char** argv, const CliCredentials& cred,
|
|||
" grpc_cli tojson <protofiles> <type>\n"
|
||||
" <protofiles> ; Comma separated list of proto files\n"
|
||||
" <type> ; Protocol buffer type name\n"
|
||||
" --proto_path ; The search path of proto files\n"
|
||||
" --proto_path ; The search paths of proto files"
|
||||
" (" GRPC_CLI_PATH_SEPARATOR
|
||||
" separated)\n"
|
||||
" --infile ; Input filename (defaults to stdin)\n"
|
||||
" --outfile ; Output filename (defaults to stdout)\n");
|
||||
|
||||
|
|
@ -983,7 +991,9 @@ bool GrpcTool::ToBinary(int argc, const char** argv, const CliCredentials& cred,
|
|||
" grpc_cli tobinary <protofiles> <type> [<message>]\n"
|
||||
" <protofiles> ; Comma separated list of proto files\n"
|
||||
" <type> ; Protocol buffer type name\n"
|
||||
" --proto_path ; The search path of proto files\n"
|
||||
" --proto_path ; The search paths of proto files"
|
||||
" (" GRPC_CLI_PATH_SEPARATOR
|
||||
" separated)\n"
|
||||
" --infile ; Input filename (defaults to stdin)\n"
|
||||
" --outfile ; Output filename (defaults to stdout)\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <unordered_set>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/str_split.h"
|
||||
|
||||
#include <grpcpp/support/config.h>
|
||||
|
||||
|
|
@ -79,7 +80,10 @@ ProtoFileParser::ProtoFileParser(const std::shared_ptr<grpc::Channel>& channel,
|
|||
|
||||
std::unordered_set<std::string> known_services;
|
||||
if (!protofiles.empty()) {
|
||||
source_tree_.MapPath("", proto_path);
|
||||
for (const absl::string_view single_path : absl::StrSplit(
|
||||
proto_path, GRPC_CLI_PATH_SEPARATOR, absl::AllowEmpty())) {
|
||||
source_tree_.MapPath("", std::string(single_path));
|
||||
}
|
||||
error_printer_ = absl::make_unique<ErrorPrinter>(this);
|
||||
importer_ = absl::make_unique<protobuf::compiler::Importer>(
|
||||
&source_tree_, error_printer_.get());
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@
|
|||
#include "test/cpp/util/config_grpc_cli.h"
|
||||
#include "test/cpp/util/proto_reflection_descriptor_database.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
#define GRPC_CLI_PATH_SEPARATOR ";"
|
||||
#else
|
||||
#define GRPC_CLI_PATH_SEPARATOR ":"
|
||||
#endif
|
||||
|
||||
namespace grpc {
|
||||
namespace testing {
|
||||
class ErrorPrinter;
|
||||
|
|
|
|||
Loading…
Reference in New Issue