Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Subcommands support separate command id #24

Merged
merged 3 commits into from
Nov 2, 2023

Conversation

lqxhub
Copy link
Collaborator

@lqxhub lqxhub commented Oct 24, 2023

每个拥有子命令的命令 (比如 config get, config set) 这样的命令, 以前的时候是一个 config 命令, 通过 第二个参数来区分具体执行哪个, config set, config get 这些命令id是同一个.

这样会带来一个问题, config set在ACL中属于写命令, config get 在ACL中属于 读命令, 如果使用 之前那种所有子命令id相同的时, 无法为子命令区分 不同的ACL类型

现在改成了 每个子命令(和redis 处理方式一样) 有单独的id, 可以为不同的子命令 区分不同的 ACL类型, 方便 权限划分

std::pair<BaseCmd*, CmdRes::CmdRet> CmdTableManager::GetCommand(const std::string& cmdName, CmdContext& ctx)
这里的返回值使用了 std::pair, 来同时返回两个值, 不知出否妥当, 如有更好的解决方法,还请指正

src/base_cmd.h Outdated Show resolved Hide resolved
src/client.cc Outdated
return 0;
}

if (!cmdPtr->CheckArg(params.size())) {
ReplyError(PError_param, &reply_);
if (cmdPtr.first->CheckArg(params.size())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该是if (!cmdPtr.first->CheckArg(params.size())) ,我在本地输入命令报错
b2f0534cfa3c3ee6dc62d145226cf25

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是判断错了,等我改一下

if (ctx.argv_.size() < 2) {
return std::pair(nullptr, CmdRes::kInvalidParameter);
}
return std::pair(cmd->second->GetSubCmd(ctx.argv_[1]), CmdRes::kSyntaxErr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里没太明白逻辑,当没有subcommand时,状态应该返回kSyntaxErr吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在调用GetCommand的地方会判断,如果有子命令,但是返回的是null, 状态是kSyntaxErr, 如果返回的指针不是null, 这个状态会被忽略

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好嘞,谢谢~

src/client.cc Outdated
return 0;
}

if (!cmdPtr->CheckArg(params.size())) {
ReplyError(PError_param, &reply_);
if (cmdPtr->CheckArg(params.size())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (cmdPtr->CheckArg(params.size())) {
if (!cmdPtr->CheckArg(params.size())) {

这里的判断条件应该是反了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对,这里是判断错了

@AlexStocks AlexStocks merged commit e05878d into OpenAtomFoundation:unstable Nov 2, 2023
1 check passed
@lqxhub lqxhub deleted the cmd branch November 13, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants