MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
defs.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by Ping Xu(haibarapink@gmail.com)
13//
14#include "common/lang/string_view.h"
15namespace oceanbase {
16
20#define DEFINE_OBLSM_CLI_CMDS \
21 DEFINE_OBLSM_CLI_CMD( \
22 OPEN, "open", "Usage: open \"DATABASE_NAME\"\nOpens a database. If the database does not exist, it is created.") \
23 DEFINE_OBLSM_CLI_CMD(CLOSE, "close", "Usage: close\nCloses the currently opened database.") \
24 DEFINE_OBLSM_CLI_CMD(SET, "set", "Usage: set \"KEY\" \"VALUE\"\nSets the value for the given key.") \
25 DEFINE_OBLSM_CLI_CMD(GET, "get", "Usage: get \"KEY\"\nGets the value associated with the given key.") \
26 DEFINE_OBLSM_CLI_CMD(DELETE, "delete", "Usage: delete \"KEY\"\nDeletes the given key.") \
27 DEFINE_OBLSM_CLI_CMD(SCAN, \
28 "scan", \
29 "Usage: scan \"KEY1\" \"KEY2\"\n" \
30 "Scans the database for keys within the specified range.\n" \
31 "The first and second keys can be specified in the following ways:\n" \
32 "- 'scan - \"KEY\"' scans from the first key in the database up to the specified key \"KEY\".\n" \
33 "- 'scan \"KEY\" -' scans from the specified key \"KEY\" to the last key in the database.\n" \
34 "- 'scan - -' scans the entire database from the first key to the last key.\n" \
35 "- 'scan \"KEY1\" \"KEY2\"' scans from the key \"KEY1\" to the key \"KEY2\".\n") \
36 DEFINE_OBLSM_CLI_CMD(HELP, "help", "") \
37 DEFINE_OBLSM_CLI_CMD(EXIT, "exit", "Usage: exit\nExits the application.")
38
39enum class ObLsmCliCmdType
40{
41#define DEFINE_OBLSM_CLI_CMD(cmd, str, help) cmd,
42 DEFINE_OBLSM_CLI_CMDS
43#undef DEFINE_OBLSM_CLI_CMD
44};
45
47{
48
49 inline static const string_view strcmd(ObLsmCliCmdType command)
50 {
51#define DEFINE_OBLSM_CLI_CMD(cmd, name, help) \
52 case ObLsmCliCmdType::cmd: { \
53 return name; \
54 } break;
55
56 switch (command) {
57 DEFINE_OBLSM_CLI_CMDS;
58 default: {
59 return "unknown";
60 }
61 }
62
63#undef DEFINE_OBLSM_CLI_CMD
64 }
65
66 inline static const string_view cmd_usage(ObLsmCliCmdType command)
67 {
68#define DEFINE_OBLSM_CLI_CMD(cmd, name, help) \
69 case ObLsmCliCmdType::cmd: { \
70 return help; \
71 } break;
72
73 switch (command) {
74 DEFINE_OBLSM_CLI_CMDS;
75 default: {
76 return "Unknown command usage.";
77 }
78 }
79
80#undef DEFINE_OBLSM_CLI_CMD
81 }
82};
83} // namespace oceanbase
Definition: defs.h:47