MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cpp-samples / parse_command_line

Function parse_command_line

populate-bucket/populate_bucket.cc:79–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79std::tuple<po::variables_map, po::options_description> parse_command_line(
80 int argc, char* argv[]) {
81 auto const default_object_count = 1'000'000L;
82 auto const default_minimum_item_size = 1'000L;
83
84 po::positional_options_description positional;
85 positional.add("action", 1);
86 po::options_description desc(
87 "Populate a GCS Bucket with randomly named objects");
88 desc.add_options()("help", "produce help message")
89 //
90 ("action", po::value<std::string>()->default_value("help")->required(),
91 "the execution mode:\n"
92 "- `schedule` to setup a number of work items in the task queue\n"
93 "- `worker` to run as a worker listening on the task queue\n"
94 "- `help` to produce some help\n")
95 //
96 ("project",
97 po::value<std::string>()->default_value(
98 getenv_or_empty("GOOGLE_CLOUD_PROJECT")),
99 "set the Google Cloud Platform project id")
100 //
101 ("subscription", po::value<std::string>(),
102 "set the Cloud Pub/Sub subscription")
103 //
104 ("topic", po::value<std::string>(), "set the Cloud Pub/Sub topic")
105 //
106 ("bucket", po::value<std::string>(), "set the destination bucket name")
107 //
108 ("object-count", po::value<long>()->default_value(default_object_count),
109 "set the number of objects created by the job")
110 //
111 ("use-hash-prefix", po::value<bool>()->default_value(true),
112 "prefix the object names with a hash to avoid hot spots in GCS")
113 //
114 ("task-size", po::value<long>()->default_value(default_minimum_item_size),
115 "each work item created by schedule-job should contain this number of "
116 "objects")
117 //
118 ("concurrency", po::value<int>()->default_value(8),
119 "number of parallel handlers to handle work items");
120
121 po::variables_map vm;
122 po::store(po::command_line_parser(argc, argv)
123 .options(desc)
124 .positional(positional)
125 .run(),
126 vm);
127 po::notify(vm);
128 std::cout << "Arguments parsed" << std::endl;
129 return {vm, desc};
130}
131
132/// Create a random object name fragment.
133std::string random_alphanum_string(std::mt19937_64& gen, int n) {

Callers 1

mainFunction · 0.70

Calls 1

getenv_or_emptyFunction · 0.85

Tested by

no test coverage detected