Apollo 10.0
自动驾驶开放平台
kv_db_tool.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
17
18#include <iostream>
19
20#include "gflags/gflags.h"
21
22#include "cyber/common/log.h"
23
24DEFINE_string(op, "get", "Operation to execute, should be put, get or del.");
25DEFINE_string(key, "", "The key to query.");
26DEFINE_string(value, "", "The value to query.");
27
29
30int main(int32_t argc, char **argv) {
31 google::InitGoogleLogging(argv[0]);
32 google::ParseCommandLineFlags(&argc, &argv, true);
33
34 if (FLAGS_key.empty()) {
35 AFATAL << "Please specify --key.";
36 }
37
38 if (FLAGS_op == "get") {
39 std::cout << KVDB::Get(FLAGS_key).value() << std::endl;
40 } else if (FLAGS_op == "put") {
41 if (FLAGS_value.empty()) {
42 AFATAL << "Please specify --value.";
43 }
44 std::cout << KVDB::Put(FLAGS_key, FLAGS_value) << std::endl;
45 } else if (FLAGS_op == "del") {
46 std::cout << KVDB::Delete(FLAGS_key) << std::endl;
47 } else {
48 AFATAL << "Unknown op: " << FLAGS_op;
49 }
50
51 return 0;
52}
Lightweight key-value database to store system-wide parameters.
Definition kv_db.h:39
static std::optional< std::string > Get(std::string_view key)
Get value of a key.
Definition kv_db.cc:107
static bool Put(std::string_view key, std::string_view value)
Store {key, value} to DB.
Definition kv_db.cc:94
static bool Delete(std::string_view key)
Delete a key.
Definition kv_db.cc:101
DEFINE_string(op, "get", "Operation to execute, should be put, get or del.")
int main(int32_t argc, char **argv)
Definition kv_db_tool.cc:30
#define AFATAL
Definition log.h:45