Skip to content

Commit 9b77138

Browse files
RomantsovScopybara-github
authored andcommitted
examples/cpp/route_guide add missing command line parsing (grpc#37857)
The gRPC basic turorial says to call the following command to run the server `./route_guide_server --db_path=path/to/route_guide_db.json` But the server and client do not parse command line arguments and they always use default value `route_guide_db.json`. Thus the example only works if we run it from `examples/cpp/route_guide` dir. Otherwise we get the following error: `helper.cc:49] Failed to open route_guide_db.json Aborted (core dumped)` Add `absl::ParseCommandLine(argc, argv);` to both server and client `main` similar to `route_guide_callback_server.cc` Closes grpc#37857 PiperOrigin-RevId: 709154601
1 parent 54cab7a commit 9b77138

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

examples/cpp/route_guide/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cc_binary(
3939
":route_guide_helper",
4040
"//:grpc++",
4141
"//examples/protos:route_guide",
42+
"@com_google_absl//absl/flags:parse",
4243
],
4344
)
4445

@@ -53,6 +54,7 @@ cc_binary(
5354
":route_guide_helper",
5455
"//:grpc++",
5556
"//examples/protos:route_guide",
57+
"@com_google_absl//absl/flags:parse",
5658
],
5759
)
5860

examples/cpp/route_guide/Makefile

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cpp/route_guide/route_guide_client.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <string>
3030
#include <thread>
3131

32+
#include "absl/flags/parse.h"
3233
#include "helper.h"
3334
#ifdef BAZEL_BUILD
3435
#include "examples/protos/route_guide.grpc.pb.h"
@@ -216,6 +217,7 @@ class RouteGuideClient {
216217
};
217218

218219
int main(int argc, char** argv) {
220+
absl::ParseCommandLine(argc, argv);
219221
// Expect only arg: --db_path=path/to/route_guide_db.json.
220222
std::string db = routeguide::GetDbFileContent(argc, argv);
221223
RouteGuideClient guide(

examples/cpp/route_guide/route_guide_server.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <memory>
3030
#include <string>
3131

32+
#include "absl/flags/parse.h"
3233
#include "helper.h"
3334
#ifdef BAZEL_BUILD
3435
#include "examples/protos/route_guide.grpc.pb.h"
@@ -182,6 +183,7 @@ void RunServer(const std::string& db_path) {
182183
}
183184

184185
int main(int argc, char** argv) {
186+
absl::ParseCommandLine(argc, argv);
185187
// Expect only arg: --db_path=path/to/route_guide_db.json.
186188
std::string db = routeguide::GetDbFileContent(argc, argv);
187189
RunServer(db);

0 commit comments

Comments
 (0)