Skip to content

Commit

Permalink
examples/cpp/route_guide add missing command line parsing (grpc#37857)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RomantsovS authored and copybara-github committed Dec 23, 2024
1 parent 54cab7a commit 9b77138
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/cpp/route_guide/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cc_binary(
":route_guide_helper",
"//:grpc++",
"//examples/protos:route_guide",
"@com_google_absl//absl/flags:parse",
],
)

Expand All @@ -53,6 +54,7 @@ cc_binary(
":route_guide_helper",
"//:grpc++",
"//examples/protos:route_guide",
"@com_google_absl//absl/flags:parse",
],
)

Expand Down
4 changes: 2 additions & 2 deletions examples/cpp/route_guide/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions examples/cpp/route_guide/route_guide_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <string>
#include <thread>

#include "absl/flags/parse.h"
#include "helper.h"
#ifdef BAZEL_BUILD
#include "examples/protos/route_guide.grpc.pb.h"
Expand Down Expand Up @@ -216,6 +217,7 @@ class RouteGuideClient {
};

int main(int argc, char** argv) {
absl::ParseCommandLine(argc, argv);
// Expect only arg: --db_path=path/to/route_guide_db.json.
std::string db = routeguide::GetDbFileContent(argc, argv);
RouteGuideClient guide(
Expand Down
2 changes: 2 additions & 0 deletions examples/cpp/route_guide/route_guide_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <memory>
#include <string>

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

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

0 comments on commit 9b77138

Please sign in to comment.