]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | // This source code is licensed under both the GPLv2 (found in the | |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
5 | ||
6 | #ifndef ROCKSDB_LITE | |
7 | #include <getopt.h> | |
1e59de90 | 8 | |
11fdf7f2 TL |
9 | #include <cstdio> |
10 | #include <string> | |
11 | #include <unordered_map> | |
12 | ||
13 | #include "utilities/blob_db/blob_dump_tool.h" | |
14 | ||
1e59de90 TL |
15 | using ROCKSDB_NAMESPACE::Status; |
16 | using ROCKSDB_NAMESPACE::blob_db::BlobDumpTool; | |
11fdf7f2 TL |
17 | |
18 | int main(int argc, char** argv) { | |
19 | using DisplayType = BlobDumpTool::DisplayType; | |
20 | const std::unordered_map<std::string, DisplayType> display_types = { | |
21 | {"none", DisplayType::kNone}, | |
22 | {"raw", DisplayType::kRaw}, | |
23 | {"hex", DisplayType::kHex}, | |
24 | {"detail", DisplayType::kDetail}, | |
25 | }; | |
26 | const struct option options[] = { | |
27 | {"help", no_argument, nullptr, 'h'}, | |
28 | {"file", required_argument, nullptr, 'f'}, | |
29 | {"show_key", optional_argument, nullptr, 'k'}, | |
30 | {"show_blob", optional_argument, nullptr, 'b'}, | |
31 | {"show_uncompressed_blob", optional_argument, nullptr, 'r'}, | |
32 | {"show_summary", optional_argument, nullptr, 's'}, | |
33 | }; | |
34 | DisplayType show_key = DisplayType::kRaw; | |
35 | DisplayType show_blob = DisplayType::kNone; | |
36 | DisplayType show_uncompressed_blob = DisplayType::kNone; | |
37 | bool show_summary = false; | |
38 | std::string file; | |
39 | while (true) { | |
40 | int c = getopt_long(argc, argv, "hk::b::f:", options, nullptr); | |
41 | if (c < 0) { | |
42 | break; | |
43 | } | |
44 | std::string arg_str(optarg ? optarg : ""); | |
45 | switch (c) { | |
46 | case 'h': | |
47 | fprintf(stdout, | |
48 | "Usage: blob_dump --file=filename " | |
49 | "[--show_key[=none|raw|hex|detail]] " | |
50 | "[--show_blob[=none|raw|hex|detail]] " | |
51 | "[--show_uncompressed_blob[=none|raw|hex|detail]] " | |
52 | "[--show_summary]\n"); | |
53 | return 0; | |
54 | case 'f': | |
55 | file = optarg; | |
56 | break; | |
57 | case 'k': | |
58 | if (optarg) { | |
59 | if (display_types.count(arg_str) == 0) { | |
60 | fprintf(stderr, "Unrecognized key display type.\n"); | |
61 | return -1; | |
62 | } | |
63 | show_key = display_types.at(arg_str); | |
64 | } | |
65 | break; | |
66 | case 'b': | |
67 | if (optarg) { | |
68 | if (display_types.count(arg_str) == 0) { | |
69 | fprintf(stderr, "Unrecognized blob display type.\n"); | |
70 | return -1; | |
71 | } | |
72 | show_blob = display_types.at(arg_str); | |
73 | } else { | |
74 | show_blob = DisplayType::kHex; | |
75 | } | |
76 | break; | |
77 | case 'r': | |
78 | if (optarg) { | |
79 | if (display_types.count(arg_str) == 0) { | |
80 | fprintf(stderr, "Unrecognized blob display type.\n"); | |
81 | return -1; | |
82 | } | |
83 | show_uncompressed_blob = display_types.at(arg_str); | |
84 | } else { | |
85 | show_uncompressed_blob = DisplayType::kHex; | |
86 | } | |
87 | break; | |
88 | case 's': | |
89 | show_summary = true; | |
90 | break; | |
91 | default: | |
92 | fprintf(stderr, "Unrecognized option.\n"); | |
93 | return -1; | |
94 | } | |
95 | } | |
96 | BlobDumpTool tool; | |
97 | Status s = | |
98 | tool.Run(file, show_key, show_blob, show_uncompressed_blob, show_summary); | |
99 | if (!s.ok()) { | |
100 | fprintf(stderr, "Failed: %s\n", s.ToString().c_str()); | |
101 | return -1; | |
102 | } | |
103 | return 0; | |
104 | } | |
105 | #else | |
106 | #include <stdio.h> | |
107 | int main(int /*argc*/, char** /*argv*/) { | |
108 | fprintf(stderr, "Not supported in lite mode.\n"); | |
109 | return -1; | |
110 | } | |
111 | #endif // ROCKSDB_LITE |